Skip to content

Commit

Permalink
Problems with Content-Length using Jetty fix #467
Browse files Browse the repository at this point in the history
  • Loading branch information
jknack committed Sep 8, 2016
1 parent 1c25477 commit e60a39e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class JettyResponse extends ServletServletResponse implements Callback {

private ServletServletRequest nreq;

private volatile boolean endRequest = true;

public JettyResponse(final ServletServletRequest nreq, final HttpServletResponse rsp) {
super(nreq.servletRequest(), rsp);
this.nreq = nreq;
Expand All @@ -57,6 +59,7 @@ public void send(final ByteBuffer buffer) throws Exception {

@Override
public void send(final InputStream stream) throws Exception {
endRequest = false;
nreq.startAsync();
sender().sendContent(Channels.newChannel(stream), this);
}
Expand All @@ -68,34 +71,40 @@ public void send(final FileChannel channel) throws Exception {
// sync version, file size is smaller than bufferSize
sender().sendContent(channel);
} else {
endRequest = false;
nreq.startAsync();
sender().sendContent(channel, this);
}
}

private HttpOutput sender() {
return ((Response) rsp).getHttpOutput();
}

@Override
public void succeeded() {
endRequest = true;
end();
}

@Override
public void failed(final Throwable cause) {
endRequest = true;
log.error("execution of " + nreq.path() + " resulted in exception", cause);
end();
}

@Override
public void end() {
super.end();
if (endRequest) {
super.end();
}
nreq = null;
}

@Override
protected void close() {
sender().close();
}

private HttpOutput sender() {
return ((Response) rsp).getHttpOutput();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class UndertowResponse implements NativeResponse {

private HttpServerExchange exchange;

private boolean endExchange = true;
private volatile boolean endExchange = true;

public UndertowResponse(final HttpServerExchange exchange) {
this.exchange = exchange;
Expand Down

0 comments on commit e60a39e

Please sign in to comment.