Skip to content

Commit

Permalink
Reason is optional in HTTP2 (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalijr2 authored Dec 19, 2021
1 parent e7934f9 commit 615b2fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion java11/src/main/java/feign/http2client/Http2Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected Response toFeignResponse(Request request, HttpResponse<byte[]> httpRes
.body(
new ByteArrayInputStream(httpResponse.body()),
length.isPresent() ? (int) length.getAsLong() : null)
.reason(httpResponse.headers().firstValue("Reason-Phrase").orElse("OK"))
.reason(httpResponse.headers().firstValue("Reason-Phrase").orElse(null))
.request(request)
.status(httpResponse.statusCode())
.headers(castMapCollectType(httpResponse.headers().map()))
Expand Down
16 changes: 15 additions & 1 deletion java11/src/test/java/feign/http2client/test/Http2ClientTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2012-2020 The Feign Authors
* Copyright 2012-2021 The Feign Authors
*
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of the License at
Expand Down Expand Up @@ -64,6 +64,20 @@ public void noResponseBodyForPatch() {
@Override
@Test
public void reasonPhraseIsOptional() throws IOException, InterruptedException {
server.enqueue(new MockResponse().setStatus("HTTP/1.1 " + 200));

final AbstractClientTest.TestInterface api =
newBuilder()
.target(AbstractClientTest.TestInterface.class, "http://localhost:" + server.getPort());

final Response response = api.post("foo");

assertThat(response.status()).isEqualTo(200);
assertThat(response.reason()).isNull();
}

@Test
public void reasonPhraseInHeader() throws IOException, InterruptedException {
server.enqueue(
new MockResponse()
.addHeader("Reason-Phrase", "There is A reason")
Expand Down

0 comments on commit 615b2fa

Please sign in to comment.