diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java index 6d66b5f738e..7177f1d4cbe 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/rest/server/Constants.java @@ -160,6 +160,7 @@ public class Constants { HashSet valXml = new HashSet(); valXml.add(CT_FHIR_XML); + valXml.add("text/xml"); valXml.add("application/xml"); valXml.add("xml"); FORMAT_VAL_XML = Collections.unmodifiableSet(valXml); @@ -169,6 +170,7 @@ public class Constants { HashSet valJson = new HashSet(); valJson.add(CT_FHIR_JSON); + valJson.add("text/json"); valJson.add("application/json"); valJson.add("json"); FORMAT_VAL_JSON = Collections.unmodifiableSet(valJson); diff --git a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java index 29fbc60d19c..4d32500ee37 100644 --- a/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java +++ b/hapi-fhir-structures-dstu/src/test/java/ca/uhn/fhir/rest/server/ServerFeaturesTest.java @@ -162,6 +162,10 @@ public class ServerFeaturesTest { } + /** + * Header value should be application/xml+fhir or application/json+fhir but + * we should also accept application/xml and application/json + */ @Test public void testAcceptHeaderNonFhirTypes() throws Exception { @@ -183,6 +187,31 @@ public class ServerFeaturesTest { } + /** + * Header value should be application/xml+fhir or application/json+fhir but + * we should also accept text/xml and text/json + */ + @Test + public void testAcceptHeaderNonFhirTypesNonStandard() throws Exception { + + HttpGet httpGet = new HttpGet("http://localhost:" + ourPort + "/Patient/1"); + httpGet.addHeader("Accept", "text/xml"); + CloseableHttpResponse status = ourClient.execute(httpGet); + String responseContent = IOUtils.toString(status.getEntity().getContent()); + IOUtils.closeQuietly(status.getEntity().getContent()); + + assertThat(responseContent, StringContains.containsString(" - + Clients (generic and annotation) did not populate the Accept header on outgoing requests. This is now populated to indicate that the client supports both XML and JSON unless the user has explicitly requested one or the other (in which case the @@ -234,6 +234,12 @@ search. This is experimental, since it is not a part of the core FHIR specification. + + Process "Accept: text/xml" and "Accept: text/json" headers was + wanting the equivalent FHIR encoding styles. These are not + correct, but the intention is clear so we will honour them + just to be helpful. +