From 35c440b7479d259b23b7edcf4b34696ec134d562 Mon Sep 17 00:00:00 2001 From: Volker Schmidt Date: Thu, 6 Sep 2018 20:59:49 +0800 Subject: [PATCH] Corrected multi-valued header value handling for JAX-RS. --- .../fhir/jaxrs/server/util/JaxRsResponse.java | 5 ++++- .../jaxrs/server/util/JaxRsResponseTest.java | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java index cb243896778..a79058e12d7 100644 --- a/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java +++ b/hapi-fhir-jaxrsserver-base/src/main/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponse.java @@ -106,7 +106,10 @@ public class JaxRsResponse extends RestfulResponse { private ResponseBuilder buildResponse(int statusCode) { ResponseBuilder response = Response.status(statusCode); for (Entry> header : getHeaders().entrySet()) { - response.header(header.getKey(), header.getValue()); + final String key = header.getKey(); + for (String value : header.getValue()) { + response.header(key, value); + } } return response; } diff --git a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseTest.java b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseTest.java index b9979da676b..c5b58275855 100644 --- a/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseTest.java +++ b/hapi-fhir-jaxrsserver-base/src/test/java/ca/uhn/fhir/jaxrs/server/util/JaxRsResponseTest.java @@ -1,6 +1,7 @@ package ca.uhn.fhir.jaxrs.server.util; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import java.io.IOException; @@ -10,6 +11,7 @@ import java.util.Set; import javax.ws.rs.core.Response; +import org.hamcrest.Matchers; import org.hl7.fhir.instance.model.api.IBaseBinary; import org.junit.Before; import org.junit.Test; @@ -108,10 +110,24 @@ public class JaxRsResponseTest { assertEquals("application/xml+fhir; charset=UTF-8", result.getHeaderString(Constants.HEADER_CONTENT_TYPE)); } + @Test + public void addMultipleHeaderValues() throws IOException { + response.addHeader("Authorization", "Basic"); + response.addHeader("Authorization", "Bearer"); + response.addHeader("Cache-Control", "no-cache, no-store"); + + final IBaseBinary binary = new Binary(); + binary.setContentType("abc"); + binary.setContent(new byte[] { 1 }); + final Response result = (Response) RestfulServerUtils.streamResponseAsResource(request.getServer(), binary, theSummaryMode, 200, false, false, this.request); + + assertThat(result.getHeaders().get("Authorization"), Matchers.contains("Basic", "Bearer")); + assertThat(result.getHeaders().get("Cache-Control"), Matchers.contains("no-cache, no-store")); + } + private Patient createPatient() { Patient theResource = new Patient(); theResource.setId(new IdDt(15L)); return theResource; } - }