@@ -158,14 +158,15 @@ public boolean handle(Request request, Response response, Callback callback)
158
158
// ClientConnector clientConnector = ClientConnector.forUnixDomain(unixDomainPath);
159
159
ClientConnector clientConnector = AFSocketClientConnector .withSocketAddress (AFUNIXSocketAddress
160
160
.of (unixDomainPath ));
161
- HttpClient httpClient = new HttpClient (new HttpClientTransportDynamic (clientConnector ));
162
- httpClient .start ();
163
- try {
164
- ContentResponse response = httpClient .newRequest (uri ).timeout (5 , TimeUnit .SECONDS ).send ();
161
+ try ( HttpClient httpClient = new HttpClient (new HttpClientTransportDynamic (clientConnector ))) {
162
+ httpClient .start ();
163
+ try {
164
+ ContentResponse response = httpClient .newRequest (uri ).timeout (5 , TimeUnit .SECONDS ).send ();
165
165
166
- assertEquals (HttpStatus .OK_200 , response .getStatus ());
167
- } finally {
168
- httpClient .stop ();
166
+ assertEquals (HttpStatus .OK_200 , response .getStatus ());
167
+ } finally {
168
+ httpClient .stop ();
169
+ }
169
170
}
170
171
}
171
172
@@ -199,16 +200,17 @@ public boolean handle(Request request, Response response, Callback callback)
199
200
fakeProxyPort ), null , new Origin .Protocol (List .of ("http/1.1" ), false ), AFSocketTransport
200
201
.withSocketChannel (unixDomainAddress )), null );
201
202
202
- HttpClient httpClient = new HttpClient (new HttpClientTransportDynamic (clientConnector ));
203
- httpClient .getProxyConfiguration ().addProxy (proxy );
204
- httpClient .start ();
205
- try {
206
- ContentResponse response = httpClient .newRequest ("localhost" , fakeServerPort ).timeout (5 ,
207
- TimeUnit .SECONDS ).send ();
203
+ try ( HttpClient httpClient = new HttpClient (new HttpClientTransportDynamic (clientConnector ))) {
204
+ httpClient .getProxyConfiguration ().addProxy (proxy );
205
+ httpClient .start ();
206
+ try {
207
+ ContentResponse response = httpClient .newRequest ("localhost" , fakeServerPort ).timeout (5 ,
208
+ TimeUnit .SECONDS ).send ();
208
209
209
- assertEquals (HttpStatus .OK_200 , response .getStatus ());
210
- } finally {
211
- httpClient .stop ();
210
+ assertEquals (HttpStatus .OK_200 , response .getStatus ());
211
+ } finally {
212
+ httpClient .stop ();
213
+ }
212
214
}
213
215
}
214
216
@@ -256,25 +258,26 @@ public boolean handle(Request request, Response response, Callback callback)
256
258
ClientConnector clientConnector = AFSocketClientConnector .withSocketAddress (AFUNIXSocketAddress
257
259
.of (unixDomainPath ));
258
260
259
- HttpClient httpClient = new HttpClient (new HttpClientTransportDynamic (clientConnector ));
260
- httpClient .start ();
261
- try {
262
- // Try PROXYv1 with the PROXY information retrieved from the EndPoint.
263
- // PROXYv1 does not support the UNIX family.
264
- ContentResponse response1 = httpClient .newRequest ("localhost" , 0 ).path ("/v1" ).tag (
265
- new V1 .Tag ()).timeout (5 , TimeUnit .SECONDS ).send ();
266
-
267
- assertEquals (HttpStatus .OK_200 , response1 .getStatus ());
268
-
269
- // Try PROXYv2 with explicit PROXY information.
270
- V2 .Tag tag = new V2 .Tag (V2 .Tag .Command .PROXY , V2 .Tag .Family .UNIX , V2 .Tag .Protocol .STREAM ,
271
- srcAddr , 0 , dstAddr , 0 , null );
272
- ContentResponse response2 = httpClient .newRequest ("localhost" , 0 ).path ("/v2" ).tag (tag )
273
- .timeout (5 , TimeUnit .SECONDS ).send ();
274
-
275
- assertEquals (HttpStatus .OK_200 , response2 .getStatus ());
276
- } finally {
277
- httpClient .stop ();
261
+ try (HttpClient httpClient = new HttpClient (new HttpClientTransportDynamic (clientConnector ))) {
262
+ httpClient .start ();
263
+ try {
264
+ // Try PROXYv1 with the PROXY information retrieved from the EndPoint.
265
+ // PROXYv1 does not support the UNIX family.
266
+ ContentResponse response1 = httpClient .newRequest ("localhost" , 0 ).path ("/v1" ).tag (
267
+ new V1 .Tag ()).timeout (5 , TimeUnit .SECONDS ).send ();
268
+
269
+ assertEquals (HttpStatus .OK_200 , response1 .getStatus ());
270
+
271
+ // Try PROXYv2 with explicit PROXY information.
272
+ V2 .Tag tag = new V2 .Tag (V2 .Tag .Command .PROXY , V2 .Tag .Family .UNIX , V2 .Tag .Protocol .STREAM ,
273
+ srcAddr , 0 , dstAddr , 0 , null );
274
+ ContentResponse response2 = httpClient .newRequest ("localhost" , 0 ).path ("/v2" ).tag (tag )
275
+ .timeout (5 , TimeUnit .SECONDS ).send ();
276
+
277
+ assertEquals (HttpStatus .OK_200 , response2 .getStatus ());
278
+ } finally {
279
+ httpClient .stop ();
280
+ }
278
281
}
279
282
}
280
283
@@ -351,16 +354,17 @@ public boolean handle(Request request, Response response, Callback callback)
351
354
// ClientConnector clientConnector = ClientConnector.forUnixDomain(unixDomainPath);
352
355
ClientConnector clientConnector = AFSocketClientConnector .withSocketAddress (AFUNIXSocketAddress
353
356
.of (unixDomainPath ));
354
- HttpClient httpClient = new HttpClient (new HttpClientTransportDynamic (clientConnector ));
355
- httpClient .start ();
356
- try {
357
- ContentResponse response = httpClient .newRequest (uri ).timeout (5 , TimeUnit .SECONDS ).send ();
357
+ try ( HttpClient httpClient = new HttpClient (new HttpClientTransportDynamic (clientConnector ))) {
358
+ httpClient .start ();
359
+ try {
360
+ ContentResponse response = httpClient .newRequest (uri ).timeout (5 , TimeUnit .SECONDS ).send ();
358
361
359
- assertEquals (HttpStatus .OK_200 , response .getStatus ());
360
- byte [] data = response .getContent ();
361
- assertArrayEquals (payload , data );
362
- } finally {
363
- httpClient .stop ();
362
+ assertEquals (HttpStatus .OK_200 , response .getStatus ());
363
+ byte [] data = response .getContent ();
364
+ assertArrayEquals (payload , data );
365
+ } finally {
366
+ httpClient .stop ();
367
+ }
364
368
}
365
369
}
366
370
}
0 commit comments