Skip to content

Commit 0bec388

Browse files
kenfinniganasoldano
authored andcommitted
[RESTEASY-2685] Merge client headers with MP REST Client
1 parent beebf5d commit 0bec388

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

resteasy-client-microprofile/src/main/java/org/jboss/resteasy/microprofile/client/header/ClientHeadersRequestFilter.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package org.jboss.resteasy.microprofile.client.header;
22

3-
import static org.jboss.resteasy.microprofile.client.utils.ListCastUtils.castToListOfStrings;
4-
53
import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory;
4+
import org.eclipse.microprofile.rest.client.ext.DefaultClientHeadersFactoryImpl;
65
import org.jboss.resteasy.microprofile.client.impl.MpClientInvocation;
76
import org.jboss.resteasy.microprofile.client.utils.ClientRequestContextUtils;
87

@@ -11,12 +10,13 @@
1110
import javax.ws.rs.client.ClientRequestFilter;
1211
import javax.ws.rs.core.MultivaluedHashMap;
1312
import javax.ws.rs.core.MultivaluedMap;
14-
1513
import java.lang.reflect.Method;
1614
import java.util.ArrayList;
1715
import java.util.List;
1816
import java.util.Optional;
1917

18+
import static org.jboss.resteasy.microprofile.client.utils.ListCastUtils.castToListOfStrings;
19+
2020

2121
/**
2222
* First the headers from `@ClientHeaderParam` annotations are applied,
@@ -52,11 +52,15 @@ public void filter(ClientRequestContext requestContext) {
5252
// stupid final rules
5353
MultivaluedMap<String,String> incomingHeaders = containerHeaders;
5454

55-
factory.map(f -> f.update(incomingHeaders, headers))
56-
.orElse(headers)
57-
.forEach(
58-
(key, values) -> requestContext.getHeaders().put(key, castToListOfObjects(values))
59-
);
55+
if (!factory.isPresent() || factory.get() instanceof DefaultClientHeadersFactoryImpl) {
56+
// When using the default factory, pass the proposed outgoing headers onto the request context.
57+
// Propagation with the default factory will then overwrite any values if required.
58+
headers.forEach((key, values) -> requestContext.getHeaders().put(key, castToListOfObjects(values)));
59+
}
60+
61+
factory.ifPresent(f -> f.update(incomingHeaders, headers)
62+
.forEach((key, values) -> requestContext.getHeaders().put(key, castToListOfObjects(values)))
63+
);
6064
}
6165

6266
private static List<Object> castToListOfObjects(List<String> values) {

0 commit comments

Comments
 (0)