Revert "Retain X-Request-ID header key casing in responses (#5787)"

This reverts commit 7742aa76c5.
This commit is contained in:
Nathan Doef 2024-03-21 12:05:50 -04:00 committed by GitHub
parent 4a726dd2d1
commit 9a53ce07f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 6 additions and 55 deletions

View File

@ -1,6 +0,0 @@
---
type: fix
issue: 5788
title: "Previously, the casing of the X-Request-ID header key was not retained in the corresponding response.
This has been fixed."

View File

@ -7,7 +7,6 @@ import ca.uhn.fhir.rest.server.exceptions.InternalErrorException;
import ca.uhn.fhir.rest.server.exceptions.PreconditionFailedException;
import ca.uhn.fhir.util.ExtensionConstants;
import org.apache.commons.io.IOUtils;
import org.apache.http.Header;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.hl7.fhir.r4.model.CapabilityStatement;
@ -16,15 +15,11 @@ import org.hl7.fhir.r4.model.CapabilityStatement.CapabilityStatementRestResource
import org.hl7.fhir.r4.model.Extension;
import org.hl7.fhir.r4.model.Patient;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -146,26 +141,4 @@ public class ServerR4Test extends BaseResourceProviderR4Test {
}
@ParameterizedTest
@ValueSource(strings = {"x-request-id", "X-Request-Id", "X-Request-ID", "X-REQUEST-ID"})
public void testXRequestIdHeaderRetainsCase(String theXRequestIdHeaderKey) throws Exception {
HttpGet get = new HttpGet(myServerBase + "/Patient");
String xRequestIdHeaderValue = "abc123";
get.addHeader(theXRequestIdHeaderKey, xRequestIdHeaderValue);
try (CloseableHttpResponse response = ourHttpClient.execute(get)) {
assertEquals(200, response.getStatusLine().getStatusCode());
String responseContent = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8);
ourLog.debug(responseContent);
List<Header> xRequestIdHeaders = Arrays.stream(response.getAllHeaders())
.filter(header -> theXRequestIdHeaderKey.equals(header.getName()))
.toList();
assertEquals(1, xRequestIdHeaders.size());
assertEquals(xRequestIdHeaderValue, xRequestIdHeaders.get(0).getValue());
}
}
}

View File

@ -1325,14 +1325,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
}
protected void addRequestIdToResponse(ServletRequestDetails theRequestDetails, String theRequestId) {
String caseSensitiveRequestIdKey = Constants.HEADER_REQUEST_ID;
for (String key : theRequestDetails.getHeaders().keySet()) {
if (Constants.HEADER_REQUEST_ID.equalsIgnoreCase(key)) {
caseSensitiveRequestIdKey = key;
break;
}
}
theRequestDetails.getResponse().addHeader(caseSensitiveRequestIdKey, theRequestId);
theRequestDetails.getResponse().addHeader(Constants.HEADER_REQUEST_ID, theRequestId);
}
/**

View File

@ -9,11 +9,6 @@ import ca.uhn.fhir.rest.api.RequestTypeEnum;
import ca.uhn.fhir.test.utilities.HttpClientExtension;
import ca.uhn.fhir.test.utilities.server.RestfulServerExtension;
import com.helger.commons.collection.iterate.EmptyEnumeration;
import jakarta.annotation.Nonnull;
import jakarta.servlet.ReadListener;
import jakarta.servlet.ServletInputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.commons.collections4.iterators.IteratorEnumeration;
import org.apache.commons.lang3.RandomStringUtils;
import org.hl7.fhir.r4.model.IdType;
@ -28,6 +23,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Assert;
import jakarta.annotation.Nonnull;
import jakarta.servlet.ReadListener;
import jakarta.servlet.ServletInputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.EOFException;
import java.io.IOException;
@ -36,9 +36,7 @@ import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Set;
import static org.apache.commons.collections.CollectionUtils.isEmpty;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
@ -111,13 +109,6 @@ public class ServerConcurrencyTest {
}
return new EmptyEnumeration<>();
});
when(myRequest.getHeaderNames()).thenAnswer(t -> {
Set<String> headerNames = myHeaders.keySet();
if (!isEmpty(headerNames)){
return new IteratorEnumeration<>(headerNames.iterator());
}
return new EmptyEnumeration<>();
});
}
/**