1717import org .eclipse .jetty .http2 .client .transport .ClientConnectionFactoryOverHTTP2 ;
1818import org .eclipse .jetty .io .ClientConnectionFactory ;
1919import org .eclipse .jetty .io .ClientConnector ;
20+ import org .eclipse .jetty .io .Transport ;
2021import org .eclipse .jetty .util .ssl .SslContextFactory ;
2122import org .junit .After ;
2223
@@ -33,25 +34,18 @@ public void tearDown() {
3334 }
3435 }
3536
36- enum Protocol {
37+ public enum Protocol {
3738 HTTP_1 ,
3839 HTTP_2 ;
3940 }
4041
4142 /**
42- * please use {@link #makeRequest(String, String, Protocol)}
43- */
44- @ Deprecated
45- public String makeRequest (String url ) throws Exception {
46- return makeRequest (null , url , Protocol .HTTP_1 );
47- }
48-
49- /**
50- * please use {@link #makeRequest(String, String, Protocol)}
43+ * @param url the URL to request
44+ * @param protocol see {@link AbstractWinstoneTest.Protocol}
45+ * @return the response
5146 */
52- @ Deprecated
53- public String makeRequest (String path , String url ) throws Exception {
54- return makeRequest (path , url , Protocol .HTTP_1 );
47+ public String makeRequest (String url , Protocol protocol ) throws Exception {
48+ return makeRequest (null , url , HttpStatus .OK_200 , protocol );
5549 }
5650
5751 /**
@@ -77,9 +71,12 @@ public String makeRequest(String path, String url, Protocol protocol) throws Exc
7771 */
7872 public String makeRequest (String path , String url , int expectedHttpStatus , Protocol protocol ) throws Exception {
7973
80- HttpClient httpClient = getHttpClient (path );
74+ HttpClient httpClient = getHttpClient ();
8175
8276 Request request = httpClient .newRequest (url );
77+ if (path != null ) {
78+ request .transport (new Transport .TCPUnix (Path .of (path )));
79+ }
8380
8481 switch (protocol ) {
8582 case HTTP_1 -> request .version (HttpVersion .HTTP_1_1 );
@@ -95,29 +92,20 @@ public String makeRequest(String path, String url, int expectedHttpStatus, Proto
9592 return response .getContentAsString ();
9693 }
9794
98- protected HttpClient getHttpClient (String path ) throws Exception {
99- HttpClient httpClient ;
100-
101- ClientConnector connector ;
95+ protected HttpClient getHttpClient () throws Exception {
96+ SslContextFactory .Client sslContextFactory = new SslContextFactory .Client (true );
97+ sslContextFactory .setHostnameVerifier ((hostname , session ) -> true );
10298
103- if (path != null ) {
104- Path unixDomainPath = Path .of (path );
105- connector = ClientConnector .forUnixDomain (unixDomainPath );
106- } else {
107- SslContextFactory .Client sslContextFactory = new SslContextFactory .Client (true );
108- sslContextFactory .setHostnameVerifier ((hostname , session ) -> true );
109-
110- connector = new ClientConnector ();
111- connector .setSslContextFactory (sslContextFactory );
112- }
99+ ClientConnector connector = new ClientConnector ();
100+ connector .setSslContextFactory (sslContextFactory );
113101
114102 ClientConnectionFactory .Info http1 = HttpClientConnectionFactory .HTTP11 ;
115103
116104 HTTP2Client http2Client = new HTTP2Client (connector );
117105 ClientConnectionFactoryOverHTTP2 .HTTP2 http2 = new ClientConnectionFactoryOverHTTP2 .HTTP2 (http2Client );
118106
119107 HttpClientTransportDynamic transport = new HttpClientTransportDynamic (connector , http1 , http2 );
120- httpClient = new HttpClient (transport );
108+ HttpClient httpClient = new HttpClient (transport );
121109 httpClient .setFollowRedirects (false );
122110 httpClient .start ();
123111 return httpClient ;
0 commit comments