@@ -51,25 +51,6 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest {
51
51
52
52
private static final Set <String > DISALLOWED_HEADERS = disallowedHeaders ();
53
53
54
- /**
55
- * By default, {@link HttpRequest} does not allow {@code Connection},
56
- * {@code Content-Length}, {@code Expect}, {@code Host}, or {@code Upgrade}
57
- * headers to be set, but this can be overriden with the
58
- * {@code jdk.httpclient.allowRestrictedHeaders} system property.
59
- * @see jdk.internal.net.http.common.Utils#getDisallowedHeaders()
60
- */
61
- private static Set <String > disallowedHeaders () {
62
- TreeSet <String > headers = new TreeSet <>(String .CASE_INSENSITIVE_ORDER );
63
- headers .addAll (Set .of ("connection" , "content-length" , "expect" , "host" , "upgrade" ));
64
-
65
- String headersToAllow = System .getProperty ("jdk.httpclient.allowRestrictedHeaders" );
66
- if (headersToAllow != null ) {
67
- Set <String > toAllow = StringUtils .commaDelimitedListToSet (headersToAllow );
68
- headers .removeAll (toAllow );
69
- }
70
- return Collections .unmodifiableSet (headers );
71
- }
72
-
73
54
74
55
private final HttpClient httpClient ;
75
56
@@ -85,13 +66,15 @@ private static Set<String> disallowedHeaders() {
85
66
86
67
public JdkClientHttpRequest (HttpClient httpClient , URI uri , HttpMethod method , Executor executor ,
87
68
@ Nullable Duration readTimeout ) {
69
+
88
70
this .httpClient = httpClient ;
89
71
this .uri = uri ;
90
72
this .method = method ;
91
73
this .executor = executor ;
92
74
this .timeout = readTimeout ;
93
75
}
94
76
77
+
95
78
@ Override
96
79
public HttpMethod getMethod () {
97
80
return this .method ;
@@ -107,7 +90,8 @@ public URI getURI() {
107
90
protected ClientHttpResponse executeInternal (HttpHeaders headers , @ Nullable Body body ) throws IOException {
108
91
try {
109
92
HttpRequest request = buildRequest (headers , body );
110
- HttpResponse <InputStream > response = this .httpClient .send (request , HttpResponse .BodyHandlers .ofInputStream ());
93
+ HttpResponse <InputStream > response =
94
+ this .httpClient .send (request , HttpResponse .BodyHandlers .ofInputStream ());
111
95
return new JdkClientHttpResponse (response );
112
96
}
113
97
catch (UncheckedIOException ex ) {
@@ -121,9 +105,7 @@ protected ClientHttpResponse executeInternal(HttpHeaders headers, @Nullable Body
121
105
122
106
123
107
private HttpRequest buildRequest (HttpHeaders headers , @ Nullable Body body ) {
124
- HttpRequest .Builder builder = HttpRequest .newBuilder ()
125
- .uri (this .uri );
126
-
108
+ HttpRequest .Builder builder = HttpRequest .newBuilder ().uri (this .uri );
127
109
if (this .timeout != null ) {
128
110
builder .timeout (this .timeout );
129
111
}
@@ -144,8 +126,7 @@ private HttpRequest.BodyPublisher bodyPublisher(HttpHeaders headers, @Nullable B
144
126
if (body != null ) {
145
127
Flow .Publisher <ByteBuffer > outputStreamPublisher = OutputStreamPublisher .create (
146
128
outputStream -> body .writeTo (StreamUtils .nonClosing (outputStream )),
147
- BYTE_MAPPER ,
148
- this .executor );
129
+ BYTE_MAPPER , this .executor );
149
130
150
131
long contentLength = headers .getContentLength ();
151
132
if (contentLength != -1 ) {
@@ -160,6 +141,25 @@ private HttpRequest.BodyPublisher bodyPublisher(HttpHeaders headers, @Nullable B
160
141
}
161
142
}
162
143
144
+ /**
145
+ * By default, {@link HttpRequest} does not allow {@code Connection},
146
+ * {@code Content-Length}, {@code Expect}, {@code Host}, or {@code Upgrade}
147
+ * headers to be set, but this can be overriden with the
148
+ * {@code jdk.httpclient.allowRestrictedHeaders} system property.
149
+ * @see jdk.internal.net.http.common.Utils#getDisallowedHeaders()
150
+ */
151
+ private static Set <String > disallowedHeaders () {
152
+ TreeSet <String > headers = new TreeSet <>(String .CASE_INSENSITIVE_ORDER );
153
+ headers .addAll (Set .of ("connection" , "content-length" , "expect" , "host" , "upgrade" ));
154
+
155
+ String headersToAllow = System .getProperty ("jdk.httpclient.allowRestrictedHeaders" );
156
+ if (headersToAllow != null ) {
157
+ Set <String > toAllow = StringUtils .commaDelimitedListToSet (headersToAllow );
158
+ headers .removeAll (toAllow );
159
+ }
160
+ return Collections .unmodifiableSet (headers );
161
+ }
162
+
163
163
164
164
private static final class ByteBufferMapper implements OutputStreamPublisher .ByteMapper <ByteBuffer > {
165
165
@@ -178,7 +178,6 @@ public ByteBuffer map(byte[] b, int off, int len) {
178
178
byteBuffer .flip ();
179
179
return byteBuffer ;
180
180
}
181
-
182
181
}
183
182
184
183
}
0 commit comments