Skip to content

Commit 615b2fa

Browse files
authored
Reason is optional in HTTP2 (#1550)
1 parent e7934f9 commit 615b2fa

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

java11/src/main/java/feign/http2client/Http2Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ protected Response toFeignResponse(Request request, HttpResponse<byte[]> httpRes
128128
.body(
129129
new ByteArrayInputStream(httpResponse.body()),
130130
length.isPresent() ? (int) length.getAsLong() : null)
131-
.reason(httpResponse.headers().firstValue("Reason-Phrase").orElse("OK"))
131+
.reason(httpResponse.headers().firstValue("Reason-Phrase").orElse(null))
132132
.request(request)
133133
.status(httpResponse.statusCode())
134134
.headers(castMapCollectType(httpResponse.headers().map()))

java11/src/test/java/feign/http2client/test/Http2ClientTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2012-2020 The Feign Authors
2+
* Copyright 2012-2021 The Feign Authors
33
*
44
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
55
* except in compliance with the License. You may obtain a copy of the License at
@@ -64,6 +64,20 @@ public void noResponseBodyForPatch() {
6464
@Override
6565
@Test
6666
public void reasonPhraseIsOptional() throws IOException, InterruptedException {
67+
server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + 200));
68+
69+
final AbstractClientTest.TestInterface api =
70+
newBuilder()
71+
.target(AbstractClientTest.TestInterface.class, "http://localhost:" + server.getPort());
72+
73+
final Response response = api.post("foo");
74+
75+
assertThat(response.status()).isEqualTo(200);
76+
assertThat(response.reason()).isNull();
77+
}
78+
79+
@Test
80+
public void reasonPhraseInHeader() throws IOException, InterruptedException {
6781
server.enqueue(
6882
new MockResponse()
6983
.addHeader("Reason-Phrase", "There is A reason")

0 commit comments

Comments
 (0)