Skip to content

Commit

Permalink
fix: Multiple headers not handled correctly in the callout response
Browse files Browse the repository at this point in the history
  • Loading branch information
aelamrani authored and brasseld committed Oct 25, 2019
1 parent 949eb8d commit 221fbf7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public class CalloutResponse {
this.response = response;
this.content = content;
this.headers = new HttpHeaders(response.headers().size());
response.headers().forEach(entry -> headers.set(entry.getKey(), entry.getValue()));

response.headers().names().forEach(headerName ->
this.headers.put(headerName, response.headers().getAll(headerName)));
}

public int getStatus() {
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/io/gravitee/policy/CalloutHttpPolicyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,28 @@ public void shouldNotProcessRequest_errorCondition() throws Exception {
verify(getRequestedFor(urlEqualTo("/")));
}

@Test
public void shouldProcessRequest_withHeaders() throws Exception {
stubFor(get(urlEqualTo("/"))
.willReturn(aResponse()
.withStatus(200)
.withBody("{\"key\": \"value\"}")
.withHeader("Header", "value1", "value2")));

when(configuration.getMethod()).thenReturn(HttpMethod.GET);
when(configuration.getUrl()).thenReturn("http://localhost:" + wireMockRule.port() + "/");
when(configuration.getVariables()).thenReturn(Collections.singletonList(
new Variable("my-headers", "{#jsonPath(#calloutResponse.headers, '$.Header')}")));

final CountDownLatch lock = new CountDownLatch(1);

new CalloutHttpPolicy(configuration).onRequest(request, response, executionContext, policyChain);

lock.await(1000, TimeUnit.MILLISECONDS);

verify(executionContext, times(1)).setAttribute(eq("my-headers"), eq("value1,value2"));
verify(policyChain, times(1)).doNext(request, response);

verify(getRequestedFor(urlEqualTo("/")));
}
}

0 comments on commit 221fbf7

Please sign in to comment.