From 1152695e281a264f8980d61fbdc17b9f8d07cc4f Mon Sep 17 00:00:00 2001 From: etff Date: Sat, 16 Mar 2024 20:41:28 +0900 Subject: [PATCH 1/3] fix: set Response.protocolVersion default value --- core/src/main/java/feign/Response.java | 4 ++-- core/src/test/java/feign/ResponseTest.java | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/feign/Response.java b/core/src/main/java/feign/Response.java index 86f6b6e7a..63d97b5b7 100644 --- a/core/src/main/java/feign/Response.java +++ b/core/src/main/java/feign/Response.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 The Feign Authors + * Copyright 2012-2024 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 @@ -125,7 +125,7 @@ public Builder request(Request request) { * HTTP protocol version */ public Builder protocolVersion(ProtocolVersion protocolVersion) { - this.protocolVersion = protocolVersion; + this.protocolVersion = (protocolVersion != null) ? protocolVersion : ProtocolVersion.HTTP_1_1; return this; } diff --git a/core/src/test/java/feign/ResponseTest.java b/core/src/test/java/feign/ResponseTest.java index 892baae3c..eea7e95cd 100644 --- a/core/src/test/java/feign/ResponseTest.java +++ b/core/src/test/java/feign/ResponseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2023 The Feign Authors + * Copyright 2012-2024 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 @@ -110,4 +110,17 @@ void statusCodesOfAnyValueAreAllowed() { assertThat(response.status()).isEqualTo(statusCode); }); } + + @Test + void protocolVersionDefaultsToHttp1_1() { + Response response = Response.builder() + .status(200) + .request(Request.create(HttpMethod.GET, "/api", Collections.emptyMap(), null, Util.UTF_8)) + .protocolVersion(null) + .body(new byte[0]) + .build(); + + assertThat(response.protocolVersion()).isEqualTo(Request.ProtocolVersion.HTTP_1_1); + assertThat(response.toString()).startsWith("HTTP/1.1 200"); + } } From aebf772db09d2f7aced5089d577325389bbc9907 Mon Sep 17 00:00:00 2001 From: etff Date: Sat, 16 Mar 2024 21:17:55 +0900 Subject: [PATCH 2/3] refactor: add default protocol version field --- core/src/main/java/feign/Response.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/feign/Response.java b/core/src/main/java/feign/Response.java index 63d97b5b7..45676d47a 100644 --- a/core/src/main/java/feign/Response.java +++ b/core/src/main/java/feign/Response.java @@ -51,6 +51,7 @@ public static Builder builder() { } public static final class Builder { + private static final ProtocolVersion DEFAULT_PROTOCOL_VERSION = ProtocolVersion.HTTP_1_1; int status; String reason; Map> headers; @@ -125,7 +126,7 @@ public Builder request(Request request) { * HTTP protocol version */ public Builder protocolVersion(ProtocolVersion protocolVersion) { - this.protocolVersion = (protocolVersion != null) ? protocolVersion : ProtocolVersion.HTTP_1_1; + this.protocolVersion = (protocolVersion != null) ? protocolVersion : DEFAULT_PROTOCOL_VERSION; return this; } From 5a3d54a4cb44f5a5e9274564a73461f41fd6aed1 Mon Sep 17 00:00:00 2001 From: etff Date: Sat, 16 Mar 2024 21:28:06 +0900 Subject: [PATCH 3/3] refactor: change to default protocol version value using builder field. --- core/src/main/java/feign/Response.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/feign/Response.java b/core/src/main/java/feign/Response.java index 45676d47a..62f1b655e 100644 --- a/core/src/main/java/feign/Response.java +++ b/core/src/main/java/feign/Response.java @@ -58,7 +58,7 @@ public static final class Builder { Body body; Request request; private RequestTemplate requestTemplate; - private ProtocolVersion protocolVersion = ProtocolVersion.HTTP_1_1; + private ProtocolVersion protocolVersion = DEFAULT_PROTOCOL_VERSION; Builder() {}