Respect all informational status codes. (#9712)

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](https://github.com/line/armeria/pull/2210) in Armeria which has forked the class for these features
This commit is contained in:
Anuraag Agrawal 2019-10-28 22:21:36 +09:00 committed by Norman Maurer
parent 34fa8cbc3d
commit 404008decf
2 changed files with 22 additions and 2 deletions

View File

@ -223,8 +223,8 @@ public final class HttpClientCodec extends CombinedChannelDuplexHandler<HttpResp
@Override @Override
protected boolean isContentAlwaysEmpty(HttpMessage msg) { protected boolean isContentAlwaysEmpty(HttpMessage msg) {
final int statusCode = ((HttpResponse) msg).status().code(); final int statusCode = ((HttpResponse) msg).status().code();
if (statusCode == 100 || statusCode == 101) { if (statusCode >= 100 && statusCode < 200) {
// 100-continue and 101 switching protocols response should be excluded from paired comparison. // An informational response should be excluded from paired comparison.
// Just delegate to super method which has all the needed handling. // Just delegate to super method which has all the needed handling.
return super.isContentAlwaysEmpty(msg); return super.isContentAlwaysEmpty(msg);
} }

View File

@ -327,6 +327,26 @@ public class HttpClientCodecTest {
assertThat(ch.readInbound(), is(nullValue())); 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 @Test
public void testMultipleResponses() { public void testMultipleResponses() {
String response = "HTTP/1.1 200 OK\r\n" + String response = "HTTP/1.1 200 OK\r\n" +