Merge remote-tracking branch 'origin/jetty-11.0.x' into jetty-12.0.x
This commit is contained in:
commit
d959b6c683
|
@ -15,10 +15,12 @@ package org.eclipse.jetty.server;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.eclipse.jetty.http.HttpField;
|
||||
import org.eclipse.jetty.http.HttpStatus;
|
||||
import org.eclipse.jetty.http.HttpTester;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
|
@ -28,6 +30,7 @@ import org.junit.jupiter.api.Disabled;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
@ -175,6 +178,58 @@ public class HttpChannelEventTest
|
|||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResponseBeginModifyHeaders() throws Exception
|
||||
{
|
||||
start(new TestHandler()
|
||||
{
|
||||
/* TODO
|
||||
@Override
|
||||
protected void handle(HttpServletRequest request, HttpServletResponse response)
|
||||
{
|
||||
response.setCharacterEncoding("utf-8");
|
||||
response.setContentType("text/plain");
|
||||
// Intentionally add two values for a header
|
||||
response.addHeader("X-Header", "foo");
|
||||
response.addHeader("X-Header", "bar");
|
||||
}
|
||||
*/
|
||||
});
|
||||
|
||||
/* TODO
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
connector.addBean(new HttpChannel.Listener()
|
||||
{
|
||||
@Override
|
||||
public void onResponseBegin(Request request)
|
||||
{
|
||||
Response response = request.getResponse();
|
||||
// Eliminate all "X-Header" values from Handler, and force it to be the one value "zed"
|
||||
response.getHttpFields().computeField("X-Header", (n, f) -> new HttpField(n, "zed"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onComplete(Request request)
|
||||
{
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
HttpTester.Request request = HttpTester.newRequest();
|
||||
request.setVersion(HttpVersion.HTTP_1_1);
|
||||
request.setHeader("Host", "localhost");
|
||||
request.setHeader("Connection", "close");
|
||||
|
||||
HttpTester.Response response = HttpTester.parseResponse(connector.getResponse(request.toString(), 5, TimeUnit.SECONDS));
|
||||
|
||||
assertTrue(latch.await(5, TimeUnit.SECONDS));
|
||||
|
||||
List<HttpField> xheaders = response.getFields("X-Header");
|
||||
assertThat("X-Header count", xheaders.size(), is(1));
|
||||
assertThat("X-Header[0].value", xheaders.get(0).getValue(), is("zed"));
|
||||
*/
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResponseFailure() throws Exception
|
||||
{
|
||||
|
@ -256,6 +311,7 @@ public class HttpChannelEventTest
|
|||
assertThat(elapsed.get(), Matchers.greaterThan(0L));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testTransientListener() throws Exception
|
||||
{
|
||||
|
|
|
@ -995,11 +995,12 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
|
|||
|
||||
if (committing)
|
||||
{
|
||||
// Let HttpChannel.Listeners modify the response before commit
|
||||
_combinedListener.onResponseBegin(_request);
|
||||
// We need an info to commit
|
||||
if (response == null)
|
||||
response = _response.newResponseMetaData();
|
||||
commit(response);
|
||||
_combinedListener.onResponseBegin(_request);
|
||||
_request.onResponseCommit();
|
||||
|
||||
// wrap callback to process informational responses
|
||||
|
|
Loading…
Reference in New Issue