Skip to content

Commit

Permalink
Issue #6642 - move shutdown logic into HttpChannelOverHTTP and HttpCo…
Browse files Browse the repository at this point in the history
…nnection

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
  • Loading branch information
lachlan-roberts committed Aug 27, 2021
1 parent fa316fc commit 949aa6c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 11 deletions.
Expand Up @@ -103,7 +103,7 @@ public void exchangeTerminated(HttpExchange exchange, Result result)
closeReason = "failure";
else if (receiver.isShutdown())
closeReason = "server close";
else if (sender.isShutdown())
else if (sender.isShutdown() && response.getStatus() != HttpStatus.SWITCHING_PROTOCOLS_101)
closeReason = "client close";

if (closeReason == null)
Expand Down
Expand Up @@ -345,15 +345,6 @@ private Result completing(ByteBuffer chunk, ByteBuffer content)
return Result.FLUSH;
}
_state = State.END;

// If this is a request, don't close the connection until the server responds.
if (_info.isRequest())
return Result.DONE;

// If successfully upgraded it is responsibility of the next protocol to close the connection.
if (_info.isResponse() && ((MetaData.Response)_info).getStatus() == HttpStatus.SWITCHING_PROTOCOLS_101)
return Result.DONE;

return Boolean.TRUE.equals(_persistent) ? Result.DONE : Result.SHUTDOWN_OUT;
}

Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.jetty.http.HttpHeaderValue;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpParser;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.http.PreEncodedHttpField;
import org.eclipse.jetty.io.AbstractConnection;
Expand Down Expand Up @@ -885,8 +886,10 @@ private void releaseChunk()
@Override
protected void onCompleteSuccess()
{
boolean upgrading = _info.getStatus() == HttpStatus.SWITCHING_PROTOCOLS_101;
release().succeeded();
if (_shutdownOut)
// If successfully upgraded it is responsibility of the next protocol to close the connection.
if (_shutdownOut && !upgrading)
getEndPoint().shutdownOutput();
}

Expand Down

0 comments on commit 949aa6c

Please sign in to comment.