Fix a bug where HttpObjectDecoder produces LastHttpContent after entering BAD_MESSAGE state
- Fixes #2103 - Added LastHttpContent.EMPTY_LAST_CONTENT.toString() for athestic reasons.
This commit is contained in:
parent
2ca7eae136
commit
b24494abeb
@ -438,7 +438,10 @@ public abstract class HttpObjectDecoder extends ReplayingDecoder<HttpObjectDecod
|
|||||||
message = createInvalidMessage();
|
message = createInvalidMessage();
|
||||||
message.setDecoderResult(DecoderResult.failure(cause));
|
message.setDecoderResult(DecoderResult.failure(cause));
|
||||||
}
|
}
|
||||||
return message;
|
|
||||||
|
HttpMessage ret = message;
|
||||||
|
message = null;
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
private HttpContent invalidChunk(Exception cause) {
|
private HttpContent invalidChunk(Exception cause) {
|
||||||
|
@ -83,6 +83,11 @@ public interface LastHttpContent extends HttpContent {
|
|||||||
public boolean release(int decrement) {
|
public boolean release(int decrement) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "EmptyLastHttpContent";
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
HttpHeaders trailingHeaders();
|
HttpHeaders trailingHeaders();
|
||||||
|
@ -451,4 +451,36 @@ public class HttpResponseDecoderTest {
|
|||||||
|
|
||||||
assertThat(ch.readInbound(), is(nullValue()));
|
assertThat(ch.readInbound(), is(nullValue()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGarbageHeaders() {
|
||||||
|
// A response without headers - from https://github.com/netty/netty/issues/2103
|
||||||
|
byte[] data = ("<html>\r\n" +
|
||||||
|
"<head><title>400 Bad Request</title></head>\r\n" +
|
||||||
|
"<body bgcolor=\"white\">\r\n" +
|
||||||
|
"<center><h1>400 Bad Request</h1></center>\r\n" +
|
||||||
|
"<hr><center>nginx/1.1.19</center>\r\n" +
|
||||||
|
"</body>\r\n" +
|
||||||
|
"</html>\r\n").getBytes();
|
||||||
|
|
||||||
|
EmbeddedChannel ch = new EmbeddedChannel(new HttpResponseDecoder());
|
||||||
|
|
||||||
|
ch.writeInbound(Unpooled.wrappedBuffer(data));
|
||||||
|
|
||||||
|
// Garbage input should generate the 999 Unknown response.
|
||||||
|
HttpResponse res = ch.readInbound();
|
||||||
|
assertThat(res.getProtocolVersion(), sameInstance(HttpVersion.HTTP_1_0));
|
||||||
|
assertThat(res.getStatus().code(), is(999));
|
||||||
|
assertThat(res.getDecoderResult().isFailure(), is(true));
|
||||||
|
assertThat(res.getDecoderResult().isFinished(), is(true));
|
||||||
|
assertThat(ch.readInbound(), is(nullValue()));
|
||||||
|
|
||||||
|
// More garbage should not generate anything (i.e. the decoder discards anything beyond this point.)
|
||||||
|
ch.writeInbound(Unpooled.wrappedBuffer(data));
|
||||||
|
assertThat(ch.readInbound(), is(nullValue()));
|
||||||
|
|
||||||
|
// Closing the connection should not generate anything since the protocol has been violated.
|
||||||
|
ch.finish();
|
||||||
|
assertThat(ch.readInbound(), is(nullValue()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user