Allow customization of disallowed JdkClientHttpRequest headers
By default, the JDK HttpClient's HttpRequest does not allow Connection, Content-Length, Expect, Host, or Upgrade headers to be set, but this can be overriden with the `jdk.httpclient.allowRestrictedHeaders` system property. See https://bugs.openjdk.org/browse/JDK-8213696 Closes gh-30787
This commit is contained in:
committed by
Arjen Poutsma
parent
2ed10f13e9
commit
9900575f9c
@@ -16,10 +16,17 @@
|
||||
|
||||
package org.springframework.http.client;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.time.Duration;
|
||||
import java.util.concurrent.Executor;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Marten Deinum
|
||||
*/
|
||||
@@ -37,4 +44,26 @@ public class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactory
|
||||
assertHttpMethod("patch", HttpMethod.PATCH);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customizeDisallowedHeaders() {
|
||||
String original = System.getProperty("jdk.httpclient.allowRestrictedHeaders");
|
||||
System.setProperty("jdk.httpclient.allowRestrictedHeaders", "host");
|
||||
|
||||
assertThat(TestJdkClientHttpRequest.DISALLOWED_HEADERS).doesNotContain("host");
|
||||
|
||||
if (original != null) {
|
||||
System.setProperty("jdk.httpclient.allowRestrictedHeaders", original);
|
||||
}
|
||||
else {
|
||||
System.clearProperty("jdk.httpclient.allowRestrictedHeaders");
|
||||
}
|
||||
}
|
||||
|
||||
static class TestJdkClientHttpRequest extends JdkClientHttpRequest {
|
||||
|
||||
public TestJdkClientHttpRequest(HttpClient httpClient, URI uri, HttpMethod method, Executor executor, Duration readTimeout) {
|
||||
super(httpClient, uri, method, executor, readTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user