Skip to content

Commit

Permalink
Respect all informational status codes. (netty#9712)
Browse files Browse the repository at this point in the history
Motivation:

HTTP 102 (WebDAV) is not correctly treated as an informational response

Modification:

Delegate all `1XX` status codes to superclass, not just `100` and `101`.

Result:

Supports WebDAV response.
Removes a huge maintenance [headache](line/armeria#2210) in Armeria which has forked the class for these features
  • Loading branch information
anuraaga authored and normanmaurer committed Oct 28, 2019
1 parent 9a473b4 commit 816350f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ private void decrement(Object msg) {
@Override
protected boolean isContentAlwaysEmpty(HttpMessage msg) {
final int statusCode = ((HttpResponse) msg).status().code();
if (statusCode == 100 || statusCode == 101) {
// 100-continue and 101 switching protocols response should be excluded from paired comparison.
if (statusCode >= 100 && statusCode < 200) {
// An informational response should be excluded from paired comparison.
// Just delegate to super method which has all the needed handling.
return super.isContentAlwaysEmpty(msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,26 @@ public void testWebSocket00Response() {
assertThat(ch.readInbound(), is(nullValue()));
}

@Test
public void testWebDavResponse() {
byte[] data = ("HTTP/1.1 102 Processing\r\n" +
"Status-URI: Status-URI:http://status.com; 404\r\n" +
"\r\n" +
"1234567812345678").getBytes();
EmbeddedChannel ch = new EmbeddedChannel(new HttpClientCodec());
assertTrue(ch.writeInbound(Unpooled.wrappedBuffer(data)));

HttpResponse res = ch.readInbound();
assertThat(res.protocolVersion(), sameInstance(HttpVersion.HTTP_1_1));
assertThat(res.status(), is(HttpResponseStatus.PROCESSING));
HttpContent content = ch.readInbound();
// HTTP 102 is not allowed to have content.
assertThat(content.content().readableBytes(), is(0));
content.release();

assertThat(ch.finish(), is(false));
}

@Test
public void testMultipleResponses() {
String response = "HTTP/1.1 200 OK\r\n" +
Expand Down

0 comments on commit 816350f

Please sign in to comment.