Skip to content

Commit

Permalink
fix issues with keep alive
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon committed Feb 21, 2024
1 parent 1d8e972 commit 71fe1d9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class HttpConnection extends NIOConnection {
private Future<?> exec = CompletableFuture.completedFuture(null);
private HttpProcessor p;

protected final ServletResponseImpl res;
protected final ServletRequestImpl req;
protected ServletResponseImpl res;
protected ServletRequestImpl req;

/**
* create new RequestBuilder
Expand All @@ -42,8 +42,6 @@ protected HttpConnection(ExecutorService executor, ServletContextImpl ctx, int k
this.executor = executor;
this.keepAliveIdle = keepAliveIdle;
this.ctx = ctx;
this.res = new ServletResponseImpl(this);
this.req = new ServletRequestImpl(this, DispatcherType.REQUEST);
}

@Override
Expand All @@ -57,6 +55,8 @@ public final void onRead() throws InterruptedException {
return;
if (!p.init(this))
return;
res = new ServletResponseImpl(this);
req = new ServletRequestImpl(this, DispatcherType.REQUEST);
exec = executor.submit(p);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ public void run() {
out.flush();
}

close = keepAliveIdle == 0 || !"keep-alive".equals(req.getHeader("connection"));
if (!close)
res.setHeader("connection", "keep-alive");
close = keepAliveIdle == 0 || !"keep-alive".equalsIgnoreCase(req.getHeader("connection"));
res.setHeader("connection", close ? "close" : "keep-alive");
events.fireRequestInitialized(req);
doRun(req, res);
events.fireRequestDestroyed(req);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,10 @@ public final void run() {
}

private final void select(long timeout, boolean close) throws IOException, InterruptedException {
if (selector.select(timeout) == 0)
return;
int l = selector.select(timeout);
onSelect(close);
if (l == 0)
return;
Iterator<SelectionKey> it = selector.selectedKeys().iterator();

while (it.hasNext()) {
Expand Down

0 comments on commit 71fe1d9

Please sign in to comment.