From 1f7ca4c74cefdeeea96d4b90be2a945d77e6905a Mon Sep 17 00:00:00 2001 From: Witalij Berdinskich Date: Mon, 20 Dec 2021 01:24:17 +0200 Subject: [PATCH] Reason is optional in HTTP2 (#1550) --- .../java/feign/http2client/Http2Client.java | 2 +- .../feign/http2client/test/Http2ClientTest.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/java11/src/main/java/feign/http2client/Http2Client.java b/java11/src/main/java/feign/http2client/Http2Client.java index 174f8e75..6b0b5ddf 100644 --- a/java11/src/main/java/feign/http2client/Http2Client.java +++ b/java11/src/main/java/feign/http2client/Http2Client.java @@ -129,7 +129,7 @@ public class Http2Client implements Client, AsyncClient { .protocolVersion(enumForName(ProtocolVersion.class, httpResponse.version())) .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())) diff --git a/java11/src/test/java/feign/http2client/test/Http2ClientTest.java b/java11/src/test/java/feign/http2client/test/Http2ClientTest.java index d5895f60..57464838 100644 --- a/java11/src/test/java/feign/http2client/test/Http2ClientTest.java +++ b/java11/src/test/java/feign/http2client/test/Http2ClientTest.java @@ -1,5 +1,5 @@ /** - * Copyright 2012-2020 The Feign Authors + * Copyright 2012-2021 The Feign Authors * * 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 @@ -67,6 +67,20 @@ public class Http2ClientTest extends AbstractClientTest { @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") .setStatus("HTTP/1.1 " + 200)); @@ -80,7 +94,6 @@ public class Http2ClientTest extends AbstractClientTest { assertThat(response.reason()).isEqualTo("There is A reason"); } - @Override @Test public void testVeryLongResponseNullLength() {