Skip to content

Commit

Permalink
Issue #8885 - Restore HttpChannel.Listener
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime committed May 22, 2023
1 parent 4a63391 commit b867cfc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void onResponseCommitted(Request request, int status, HttpFields response
{
try
{
onResponseCommittedHandle.invoke(request, response);
onResponseCommittedHandle.invoke(request, status, response);
}
catch (Throwable ignore)
{
Expand All @@ -205,7 +205,7 @@ public void onResponseWrite(Request request, boolean last, ByteBuffer content, T
{
try
{
onResponseWriteHandle.invoke(request, last, content);
onResponseWriteHandle.invoke(request, last, content, failure);
}
catch (Throwable ignore)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public Runnable onRequest(MetaData.Request request)
if (_request != null)
throw new IllegalStateException("duplicate request");
_request = new ChannelRequest(this, request);
_response = new ChannelResponse(_request);
_response = new ChannelResponse(this, _request);

HttpFields.Mutable responseHeaders = _response.getHeaders();
if (getHttpConfiguration().getSendServerVersion())
Expand Down Expand Up @@ -354,7 +354,7 @@ public Runnable onFailure(Throwable x)
// If the channel doesn't have a request, then the error must have occurred during the parsing of
// the request line / headers, so make a temp request for logging and producing an error response.
_request = new ChannelRequest(this, ERROR_REQUEST);
_response = new ChannelResponse(_request);
_response = new ChannelResponse(this, _request);
}

// Set the error to arrange for any subsequent reads, demands or writes to fail.
Expand Down Expand Up @@ -545,6 +545,7 @@ public void run()
Server server = _connectionMetaData.getConnector().getServer();

boolean handled = false;
Throwable failure = null;
try
{
if (!HttpMethod.PRI.is(request.getMethod()) &&
Expand Down Expand Up @@ -586,11 +587,12 @@ public void run()
catch (Throwable t)
{
request._callback.failed(t);
failure = t;
}

_combinedListener.onAfterHandling(request, handled, failure);

HttpStream stream;
Throwable failure;
boolean completeStream;
boolean callbackCompleted;
boolean lastStreamSendComplete;
Expand Down Expand Up @@ -716,8 +718,7 @@ public static class ChannelRequest implements Attributes, Request
_id = httpChannelState.getHttpStream().getId(); // Copy ID now, as stream will ultimately be nulled
_connectionMetaData = httpChannelState.getConnectionMetaData();
_metaData = Objects.requireNonNull(metaData);
_listener = httpChannel._combinedListener;
_response = new ChannelResponse(this, _listener);
_listener = httpChannelState._combinedListener;
_lock = httpChannelState._lock;
}

Expand Down Expand Up @@ -1034,10 +1035,10 @@ public static class ChannelResponse implements Response, Callback
private Callback _writeCallback;
protected boolean _errorMode;

private ChannelResponse(ChannelRequest request, HttpChannel.Listener listener)
private ChannelResponse(HttpChannelState httpChannelState, ChannelRequest request)
{
_request = request;
_listener = listener;
_listener = httpChannelState._combinedListener;
}

private void lockedPrepareErrorResponse()
Expand Down Expand Up @@ -1208,7 +1209,7 @@ public void failed(Throwable x)
}

Throwable t = failure;
httpChannel._serializedInvoker.run(() ->
httpChannelState._serializedInvoker.run(() ->
{
_listener.onResponseWrite(_request, last, content.slice(), t);
callback.succeeded();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public void dispose()
Foo, Bar
This is the Request, This is the Response
""")
@Disabled("re-enable once PR #9684 is merged")
public void testRequestReadResponseWrite(String requestBody, String expectedResponseBody) throws Exception
{
start(new Handler.Abstract()
Expand Down Expand Up @@ -250,7 +249,6 @@ public void onRequestRead(Request request, Content.Chunk chunk)
}

@Test
@Disabled("re-enable once PR #9684 is merged")
public void testResponseContentSlice() throws Exception
{
byte[] data = new byte[]{'y'};
Expand Down

0 comments on commit b867cfc

Please sign in to comment.