|
1 | 1 | package org.jboss.resteasy.microprofile.client.header;
|
2 | 2 |
|
3 |
| -import static org.jboss.resteasy.microprofile.client.utils.ListCastUtils.castToListOfStrings; |
4 |
| - |
5 | 3 | import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory;
|
| 4 | +import org.eclipse.microprofile.rest.client.ext.DefaultClientHeadersFactoryImpl; |
6 | 5 | import org.jboss.resteasy.microprofile.client.impl.MpClientInvocation;
|
7 | 6 | import org.jboss.resteasy.microprofile.client.utils.ClientRequestContextUtils;
|
8 | 7 |
|
|
11 | 10 | import javax.ws.rs.client.ClientRequestFilter;
|
12 | 11 | import javax.ws.rs.core.MultivaluedHashMap;
|
13 | 12 | import javax.ws.rs.core.MultivaluedMap;
|
14 |
| - |
15 | 13 | import java.lang.reflect.Method;
|
16 | 14 | import java.util.ArrayList;
|
17 | 15 | import java.util.List;
|
18 | 16 | import java.util.Optional;
|
19 | 17 |
|
| 18 | +import static org.jboss.resteasy.microprofile.client.utils.ListCastUtils.castToListOfStrings; |
| 19 | + |
20 | 20 |
|
21 | 21 | /**
|
22 | 22 | * First the headers from `@ClientHeaderParam` annotations are applied,
|
@@ -52,11 +52,15 @@ public void filter(ClientRequestContext requestContext) {
|
52 | 52 | // stupid final rules
|
53 | 53 | MultivaluedMap<String,String> incomingHeaders = containerHeaders;
|
54 | 54 |
|
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 | + ); |
60 | 64 | }
|
61 | 65 |
|
62 | 66 | private static List<Object> castToListOfObjects(List<String> values) {
|
|
0 commit comments