Strip http 'expect' headers when expectation response is produced
Motivation: HttpObjectAggregator differs from HttpServerExpectContinueHandler's handling of expect headers by not stripping the 'expect' header when a response is generated. Modifications: HttpObjectAggregator now removes the 'expect' header in cases where it generates a response. Result: Consistent and correct behavior between HttpObjectAggregator and HttpServerExpectContinueHandler.
This commit is contained in:
parent
8be9a63c1c
commit
52e19d5c63
@ -30,6 +30,7 @@ import io.netty.util.internal.logging.InternalLoggerFactory;
|
|||||||
|
|
||||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONNECTION;
|
import static io.netty.handler.codec.http.HttpHeaderNames.CONNECTION;
|
||||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
|
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
|
||||||
|
import static io.netty.handler.codec.http.HttpHeaderNames.EXPECT;
|
||||||
import static io.netty.handler.codec.http.HttpUtil.getContentLength;
|
import static io.netty.handler.codec.http.HttpUtil.getContentLength;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -158,8 +159,7 @@ public class HttpObjectAggregator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private Object continueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) {
|
||||||
protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) {
|
|
||||||
if (HttpUtil.isUnsupportedExpectation(start)) {
|
if (HttpUtil.isUnsupportedExpectation(start)) {
|
||||||
// if the request contains an unsupported expectation, we return 417
|
// if the request contains an unsupported expectation, we return 417
|
||||||
pipeline.fireUserEventTriggered(HttpExpectationFailedEvent.INSTANCE);
|
pipeline.fireUserEventTriggered(HttpExpectationFailedEvent.INSTANCE);
|
||||||
@ -176,6 +176,17 @@ public class HttpObjectAggregator
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Object newContinueResponse(HttpMessage start, int maxContentLength, ChannelPipeline pipeline) {
|
||||||
|
Object response = continueResponse(start, maxContentLength, pipeline);
|
||||||
|
// we're going to respond based on the request expectation so there's no
|
||||||
|
// need to propagate the expectation further.
|
||||||
|
if (response != null) {
|
||||||
|
start.headers().remove(EXPECT);
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean closeAfterContinueResponse(Object msg) {
|
protected boolean closeAfterContinueResponse(Object msg) {
|
||||||
return closeOnExpectationFailed && ignoreContentAfterContinueResponse(msg);
|
return closeOnExpectationFailed && ignoreContentAfterContinueResponse(msg);
|
||||||
|
@ -370,6 +370,23 @@ public class HttpObjectAggregatorTest {
|
|||||||
assertFalse(embedder.finish());
|
assertFalse(embedder.finish());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testValidRequestWith100ContinueAndDecoder() {
|
||||||
|
EmbeddedChannel embedder = new EmbeddedChannel(new HttpRequestDecoder(), new HttpObjectAggregator(100));
|
||||||
|
embedder.writeInbound(Unpooled.copiedBuffer(
|
||||||
|
"GET /upload HTTP/1.1\r\n" +
|
||||||
|
"Expect: 100-continue\r\n" +
|
||||||
|
"Content-Length: 0\r\n\r\n", CharsetUtil.US_ASCII));
|
||||||
|
|
||||||
|
FullHttpResponse response = embedder.readOutbound();
|
||||||
|
assertEquals(HttpResponseStatus.CONTINUE, response.status());
|
||||||
|
FullHttpRequest request = embedder.readInbound();
|
||||||
|
assertFalse(request.headers().contains(HttpHeaderNames.EXPECT));
|
||||||
|
request.release();
|
||||||
|
response.release();
|
||||||
|
assertFalse(embedder.finish());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOversizedRequestWith100ContinueAndDecoder() {
|
public void testOversizedRequestWith100ContinueAndDecoder() {
|
||||||
EmbeddedChannel embedder = new EmbeddedChannel(new HttpRequestDecoder(), new HttpObjectAggregator(4));
|
EmbeddedChannel embedder = new EmbeddedChannel(new HttpRequestDecoder(), new HttpObjectAggregator(4));
|
||||||
|
Loading…
Reference in New Issue
Block a user