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:
parent
34fa8cbc3d
commit
404008decf
@ -223,8 +223,8 @@ public final class HttpClientCodec extends CombinedChannelDuplexHandler<HttpResp
|
||||
@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);
|
||||
}
|
||||
|
@ -327,6 +327,26 @@ public class HttpClientCodecTest {
|
||||
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" +
|
||||
|
Loading…
Reference in New Issue
Block a user