Skip to content

Commit 09e7b2a

Browse files
committed
netty: don't send headers twice
1 parent 90ac63e commit 09e7b2a

3 files changed

Lines changed: 16 additions & 68 deletions

File tree

jooby-netty/src/main/java/org/jooby/internal/netty/NettyOutputStream.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class NettyOutputStream extends OutputStream {
6666

6767
private HttpHeaders headers;
6868

69+
private boolean committed;
70+
6971
NettyOutputStream(final NettyResponse rsp, final ChannelHandlerContext ctx, final ByteBuf buffer,
7072
final boolean keepAlive, final HttpHeaders headers) {
7173
this.rsp = rsp;
@@ -90,6 +92,10 @@ public void reset() {
9092
buffer.clear();
9193
}
9294

95+
public boolean committed() {
96+
return committed;
97+
}
98+
9399
@Override
94100
public void close() throws IOException {
95101
try {
@@ -163,12 +169,13 @@ public void flush() throws IOException {
163169
rsp.headers().set(headers);
164170
ctx.writeAndFlush(rsp).addListener(FIRE_EXCEPTION_ON_FAILURE);
165171
}
172+
committed = true;
166173
return;
167174
}
168175
/**
169176
* Case 1; we need to send chunks and check if content-length was set or not.
170177
*/
171-
if (chunkState == 1) {
178+
if (chunkState == 1 && !committed) {
172179
/**
173180
* Set headers, if Content-Length wasn't set force/set Transfer-Encoding
174181
*/
@@ -188,6 +195,7 @@ public void flush() throws IOException {
188195
// send headers
189196
ctx.write(rsp).addListener(FIRE_EXCEPTION_ON_FAILURE);
190197
}
198+
committed = true;
191199
/**
192200
* Write chunk and clear the buffer.
193201
*/

jooby-netty/src/main/java/org/jooby/internal/netty/NettyResponse.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,13 @@ public void statusCode(final int code) {
124124

125125
@Override
126126
public boolean committed() {
127-
return ctx == null;
127+
if (ctx == null) {
128+
return true;
129+
}
130+
if (out != null) {
131+
return out.committed();
132+
}
133+
return false;
128134
}
129135

130136
@Override

md/overview.md

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)