Fixes #959 - CompleteListener invoked twice for HTTP/2 transport and response content.
This commit is contained in:
parent
f3751da475
commit
a1a132a601
|
@ -162,8 +162,14 @@ public class HttpReceiverOverHTTP2 extends HttpReceiver implements Stream.Listen
|
|||
{
|
||||
dataInfo = queue.poll();
|
||||
}
|
||||
|
||||
if (dataInfo == null)
|
||||
{
|
||||
DataInfo prevDataInfo = this.dataInfo;
|
||||
if (prevDataInfo != null && prevDataInfo.last)
|
||||
return Action.SUCCEEDED;
|
||||
return Action.IDLE;
|
||||
}
|
||||
|
||||
this.dataInfo = dataInfo;
|
||||
responseContent(dataInfo.exchange, dataInfo.buffer, this);
|
||||
|
@ -176,11 +182,15 @@ public class HttpReceiverOverHTTP2 extends HttpReceiver implements Stream.Listen
|
|||
ByteBufferPool byteBufferPool = getHttpDestination().getHttpClient().getByteBufferPool();
|
||||
byteBufferPool.release(dataInfo.buffer);
|
||||
dataInfo.callback.succeeded();
|
||||
if (dataInfo.last)
|
||||
responseSuccess(dataInfo.exchange);
|
||||
super.succeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCompleteSuccess()
|
||||
{
|
||||
responseSuccess(dataInfo.exchange);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCompleteFailure(Throwable failure)
|
||||
{
|
||||
|
|
|
@ -483,6 +483,28 @@ public class HttpClientTest extends AbstractTest
|
|||
Assert.assertTrue(completeLatch.await(5, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResponseWithContentCompleteListenerInvokedOnce() throws Exception
|
||||
{
|
||||
start(new EmptyServerHandler()
|
||||
{
|
||||
@Override
|
||||
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
|
||||
{
|
||||
super.handle(target, baseRequest, request, response);
|
||||
response.getWriter().write("Jetty");
|
||||
}
|
||||
});
|
||||
|
||||
AtomicInteger completes = new AtomicInteger();
|
||||
client.newRequest(newURI())
|
||||
.send(result -> completes.incrementAndGet());
|
||||
|
||||
sleep(1000);
|
||||
|
||||
Assert.assertEquals(1, completes.get());
|
||||
}
|
||||
|
||||
private void sleep(long time) throws IOException
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Reference in New Issue