Skip to content

Commit 738dd18

Browse files
committed
refactor: pass produces values directly to header via varargs
Signed-off-by: Segergren <olle.segergren@gmail.com>
1 parent 1803c11 commit 738dd18

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

spring-cloud-openfeign-core/src/main/java/org/springframework/cloud/openfeign/support/SpringMvcContract.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.List;
3131
import java.util.Map;
3232
import java.util.Objects;
33-
import java.util.stream.Collectors;
3433

3534
import feign.Contract;
3635
import feign.Feign;
@@ -419,11 +418,11 @@ private boolean queryMapParamPresent(MethodMetadata data) {
419418
}
420419

421420
private void parseProduces(MethodMetadata md, RequestMapping annotation) {
422-
String clientAccepts = Arrays.stream(annotation.produces())
421+
String[] clientAccepts = Arrays.stream(annotation.produces())
423422
.map(s -> emptyToNull(s))
424423
.filter(Objects::nonNull)
425-
.collect(Collectors.joining(", "));
426-
if (StringUtils.hasText(clientAccepts)) {
424+
.toArray(String[]::new);
425+
if (clientAccepts.length > 0) {
427426
md.template().header(ACCEPT, clientAccepts);
428427
}
429428
}

spring-cloud-openfeign-core/src/test/java/org/springframework/cloud/openfeign/support/SpringMvcContractTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ void testMultipleProducesValues() throws NoSuchMethodException {
769769
Method method = TestTemplate_MultipleProduces.class.getDeclaredMethod("multipleProduces");
770770
MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
771771

772-
assertThat(data.template().headers().get("Accept")).containsExactly("application/jose, application/json");
772+
assertThat(data.template().headers().get("Accept")).containsExactly("application/jose", "application/json");
773773
}
774774

775775
@Test
@@ -793,7 +793,7 @@ void testProducesWithBlankEntryIgnored() throws NoSuchMethodException {
793793
Method method = TestTemplate_MultipleProduces.class.getDeclaredMethod("producesWithBlankEntry");
794794
MethodMetadata data = contract.parseAndValidateMetadata(method.getDeclaringClass(), method);
795795

796-
assertThat(data.template().headers().get("Accept")).containsExactly("application/jose, application/json");
796+
assertThat(data.template().headers().get("Accept")).containsExactly("application/jose", "application/json");
797797
}
798798

799799
@Test

0 commit comments

Comments
 (0)