Skip to content

Commit

Permalink
[RESTEASY-2685] Merge client headers with MP REST Client
Browse files Browse the repository at this point in the history
  • Loading branch information
kenfinnigan authored and asoldano committed Sep 18, 2020
1 parent beebf5d commit 0bec388
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.jboss.resteasy.microprofile.client.header;

import static org.jboss.resteasy.microprofile.client.utils.ListCastUtils.castToListOfStrings;

import org.eclipse.microprofile.rest.client.ext.ClientHeadersFactory;
import org.eclipse.microprofile.rest.client.ext.DefaultClientHeadersFactoryImpl;
import org.jboss.resteasy.microprofile.client.impl.MpClientInvocation;
import org.jboss.resteasy.microprofile.client.utils.ClientRequestContextUtils;

Expand All @@ -11,12 +10,13 @@
import javax.ws.rs.client.ClientRequestFilter;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static org.jboss.resteasy.microprofile.client.utils.ListCastUtils.castToListOfStrings;


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

factory.map(f -> f.update(incomingHeaders, headers))
.orElse(headers)
.forEach(
(key, values) -> requestContext.getHeaders().put(key, castToListOfObjects(values))
);
if (!factory.isPresent() || factory.get() instanceof DefaultClientHeadersFactoryImpl) {
// When using the default factory, pass the proposed outgoing headers onto the request context.
// Propagation with the default factory will then overwrite any values if required.
headers.forEach((key, values) -> requestContext.getHeaders().put(key, castToListOfObjects(values)));
}

factory.ifPresent(f -> f.update(incomingHeaders, headers)
.forEach((key, values) -> requestContext.getHeaders().put(key, castToListOfObjects(values)))
);
}

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

0 comments on commit 0bec388

Please sign in to comment.