Skip to content

Commit 0b4e653

Browse files
committed
Upgraded HttpCore to version 5.3-beta1
1 parent 0b4b06d commit 0b4e653

5 files changed

Lines changed: 100 additions & 65 deletions

File tree

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestCookieVirtualHost.java

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,37 @@
3333
import org.apache.hc.client5.http.cookie.BasicCookieStore;
3434
import org.apache.hc.client5.http.cookie.Cookie;
3535
import org.apache.hc.client5.http.cookie.CookieStore;
36+
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
37+
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
3638
import org.apache.hc.client5.http.protocol.HttpClientContext;
37-
import org.apache.hc.client5.testing.extension.sync.ClientProtocolLevel;
38-
import org.apache.hc.client5.testing.extension.sync.TestClient;
3939
import org.apache.hc.core5.http.HttpHost;
4040
import org.apache.hc.core5.http.HttpStatus;
41-
import org.apache.hc.core5.http.URIScheme;
41+
import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
42+
import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
4243
import org.apache.hc.core5.http.io.entity.EntityUtils;
4344
import org.apache.hc.core5.http.message.BasicHeader;
45+
import org.apache.hc.core5.io.CloseMode;
46+
import org.junit.jupiter.api.AfterEach;
4447
import org.junit.jupiter.api.Assertions;
4548
import org.junit.jupiter.api.Test;
4649

4750
/**
4851
* This class tests cookie matching when using Virtual Host.
4952
*/
50-
public class TestCookieVirtualHost extends AbstractIntegrationTestBase {
53+
public class TestCookieVirtualHost {
5154

52-
public TestCookieVirtualHost() {
53-
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
55+
private HttpServer server;
56+
57+
@AfterEach
58+
public void shutDown() throws Exception {
59+
if (this.server != null) {
60+
this.server.close(CloseMode.GRACEFUL);
61+
}
5462
}
5563

5664
@Test
5765
public void testCookieMatchingWithVirtualHosts() throws Exception {
58-
configureServer(bootstrap -> bootstrap
66+
server = ServerBootstrap.bootstrap()
5967
.register("app.mydomain.fr", "*", (request, response, context) -> {
6068

6169
final int n = Integer.parseInt(request.getFirstHeader("X-Request").getValue());
@@ -93,45 +101,49 @@ public void testCookieMatchingWithVirtualHosts() throws Exception {
93101
Assertions.fail("Unexpected value: " + n);
94102
break;
95103
}
96-
}));
97-
98-
final HttpHost target = startServer();
99-
100-
final TestClient client = client();
101-
102-
final CookieStore cookieStore = new BasicCookieStore();
103-
final HttpClientContext context = HttpClientContext.create();
104-
context.setCookieStore(cookieStore);
105-
106-
// First request : retrieve a domain cookie from remote server.
107-
final HttpGet request1 = new HttpGet(new URI("http://app.mydomain.fr"));
108-
request1.addHeader("X-Request", "1");
109-
client.execute(target, request1, context, response -> {
110-
EntityUtils.consume(response.getEntity());
111-
return null;
112-
});
113-
114-
// We should have one cookie set on domain.
115-
final List<Cookie> cookies = cookieStore.getCookies();
116-
Assertions.assertNotNull(cookies);
117-
Assertions.assertEquals(1, cookies.size());
118-
Assertions.assertEquals("name1", cookies.get(0).getName());
119-
120-
// Second request : send the cookie back.
121-
final HttpGet request2 = new HttpGet(new URI("http://app.mydomain.fr"));
122-
request2.addHeader("X-Request", "2");
123-
client.execute(target, request2, context, response -> {
124-
EntityUtils.consume(response.getEntity());
125-
return null;
126-
});
127-
128-
// Third request : Host header
129-
final HttpGet request3 = new HttpGet(new URI("http://app.mydomain.fr"));
130-
request3.addHeader("X-Request", "3");
131-
client.execute(target, request3, context, response -> {
132-
EntityUtils.consume(response.getEntity());
133-
return null;
134-
});
104+
})
105+
.create();
106+
server.start();
107+
108+
final HttpHost target = new HttpHost("localhost", server.getLocalPort());
109+
try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
110+
final CookieStore cookieStore = new BasicCookieStore();
111+
final HttpClientContext context = HttpClientContext.create();
112+
context.setCookieStore(cookieStore);
113+
114+
// First request : retrieve a domain cookie from remote server.
115+
final HttpGet request1 = new HttpGet(new URI("http://app.mydomain.fr"));
116+
request1.addHeader("X-Request", "1");
117+
client.execute(target, request1, context, response -> {
118+
Assertions.assertEquals(200, response.getCode());
119+
EntityUtils.consume(response.getEntity());
120+
return null;
121+
});
122+
123+
// We should have one cookie set on domain.
124+
final List<Cookie> cookies = cookieStore.getCookies();
125+
Assertions.assertNotNull(cookies);
126+
Assertions.assertEquals(1, cookies.size());
127+
Assertions.assertEquals("name1", cookies.get(0).getName());
128+
129+
// Second request : send the cookie back.
130+
final HttpGet request2 = new HttpGet(new URI("http://app.mydomain.fr"));
131+
request2.addHeader("X-Request", "2");
132+
client.execute(target, request2, context, response -> {
133+
Assertions.assertEquals(200, response.getCode());
134+
EntityUtils.consume(response.getEntity());
135+
return null;
136+
});
137+
138+
// Third request : Host header
139+
final HttpGet request3 = new HttpGet(new URI("http://app.mydomain.fr"));
140+
request3.addHeader("X-Request", "3");
141+
client.execute(target, request3, context, response -> {
142+
Assertions.assertEquals(200, response.getCode());
143+
EntityUtils.consume(response.getEntity());
144+
return null;
145+
});
146+
}
135147
}
136148

137149
}

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestDefaultClientTlsStrategy.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public void testBasicSSL() throws Exception {
100100
// @formatter:off
101101
this.server = ServerBootstrap.bootstrap()
102102
.setSslContext(SSLTestContexts.createServerSSLContext())
103+
.setRequestRouter((r, c) -> null)
103104
.create();
104105
// @formatter:on
105106
this.server.start();
@@ -129,6 +130,7 @@ public void testBasicDefaultHostnameVerifier() throws Exception {
129130
// @formatter:off
130131
this.server = ServerBootstrap.bootstrap()
131132
.setSslContext(SSLTestContexts.createServerSSLContext())
133+
.setRequestRouter((r, c) -> null)
132134
.create();
133135
// @formatter:on
134136
this.server.start();
@@ -155,6 +157,7 @@ public void testClientAuthSSL() throws Exception {
155157
// @formatter:off
156158
this.server = ServerBootstrap.bootstrap()
157159
.setSslContext(SSLTestContexts.createServerSSLContext())
160+
.setRequestRouter((r, c) -> null)
158161
.create();
159162
// @formatter:on
160163
this.server.start();
@@ -185,6 +188,7 @@ public void testClientAuthSSLFailure() throws Exception {
185188
this.server = ServerBootstrap.bootstrap()
186189
.setSslContext(SSLTestContexts.createServerSSLContext())
187190
.setSslSetupHandler(sslParameters -> sslParameters.setNeedClientAuth(true))
191+
.setRequestRouter((r, c) -> null)
188192
.create();
189193
// @formatter:on
190194
this.server.start();
@@ -217,6 +221,7 @@ public void testSSLTrustVerification() throws Exception {
217221
// @formatter:off
218222
this.server = ServerBootstrap.bootstrap()
219223
.setSslContext(SSLTestContexts.createServerSSLContext())
224+
.setRequestRouter((r, c) -> null)
220225
.create();
221226
// @formatter:on
222227
this.server.start();
@@ -250,6 +255,7 @@ private void testSSLTrustVerificationOverride(final TrustStrategy trustStrategy)
250255
// @formatter:off
251256
this.server = ServerBootstrap.bootstrap()
252257
.setSslContext(SSLTestContexts.createServerSSLContext())
258+
.setRequestRouter((r, c) -> null)
253259
.create();
254260
// @formatter:on
255261
this.server.start();
@@ -283,6 +289,7 @@ public void testSSLDisabledByDefault() throws Exception {
283289
this.server = ServerBootstrap.bootstrap()
284290
.setSslContext(SSLTestContexts.createServerSSLContext())
285291
.setSslSetupHandler(sslParameters -> sslParameters.setProtocols(new String[] {"SSLv3"}))
292+
.setRequestRouter((r, c) -> null)
286293
.create();
287294
// @formatter:on
288295
this.server.start();
@@ -335,6 +342,7 @@ private void testWeakCipherDisabledByDefault(final String cipherSuite) throws Ex
335342
this.server = ServerBootstrap.bootstrap()
336343
.setSslContext(SSLTestContexts.createServerSSLContext())
337344
.setSslSetupHandler(sslParameters -> sslParameters.setProtocols(new String[] {cipherSuite}))
345+
.setRequestRouter((r, c) -> null)
338346
.create();
339347
// @formatter:on
340348
this.server.start();
@@ -358,6 +366,7 @@ public void testHostnameVerificationClient() throws Exception {
358366
// @formatter:off
359367
this.server = ServerBootstrap.bootstrap()
360368
.setSslContext(SSLTestContexts.createServerSSLContext())
369+
.setRequestRouter((r, c) -> null)
361370
.create();
362371
// @formatter:on
363372
this.server.start();
@@ -419,6 +428,7 @@ public void testHostnameVerificationBuiltIn() throws Exception {
419428
// @formatter:off
420429
this.server = ServerBootstrap.bootstrap()
421430
.setSslContext(SSLTestContexts.createServerSSLContext())
431+
.setRequestRouter((r, c) -> null)
422432
.create();
423433
// @formatter:on
424434
this.server.start();

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestFutureRequestExecutionService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public class TestFutureRequestExecutionService {
7272
@BeforeEach
7373
public void before() throws Exception {
7474
this.localServer = ServerBootstrap.bootstrap()
75+
.setCanonicalHostName("localhost")
7576
.register("/wait", (request, response, context) -> {
7677
try {
7778
while(blocked.get()) {

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestMalformedServerResponse.java

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,22 @@
4343
import org.apache.hc.core5.http.io.HttpConnectionFactory;
4444
import org.apache.hc.core5.http.io.entity.EntityUtils;
4545
import org.apache.hc.core5.http.io.entity.StringEntity;
46+
import org.apache.hc.core5.io.CloseMode;
47+
import org.junit.jupiter.api.AfterEach;
4648
import org.junit.jupiter.api.Assertions;
4749
import org.junit.jupiter.api.Test;
4850

4951
public class TestMalformedServerResponse {
5052

53+
private HttpServer server;
54+
55+
@AfterEach
56+
public void shutDown() throws Exception {
57+
if (this.server != null) {
58+
this.server.close(CloseMode.GRACEFUL);
59+
}
60+
}
61+
5162
static class BrokenServerConnection extends DefaultBHttpServerConnection {
5263

5364
public BrokenServerConnection(final String scheme, final Http1Config h1Config) {
@@ -85,30 +96,31 @@ public DefaultBHttpServerConnection createConnection(final Socket socket) throws
8596

8697
@Test
8798
public void testNoContentResponseWithGarbage() throws Exception {
88-
try (final HttpServer server = ServerBootstrap.bootstrap()
99+
server = ServerBootstrap.bootstrap()
100+
.setCanonicalHostName("localhost")
89101
.setConnectionFactory(new BrokenServerConnectionFactory())
90102
.register("/nostuff", (request, response, context) -> response.setCode(HttpStatus.SC_NO_CONTENT))
91103
.register("/stuff", (request, response, context) -> {
92104
response.setCode(HttpStatus.SC_OK);
93105
response.setEntity(new StringEntity("Some important stuff"));
94106
})
95-
.create()) {
96-
server.start();
97-
final HttpHost target = new HttpHost("localhost", server.getLocalPort());
98-
try (final CloseableHttpClient httpclient = HttpClientBuilder.create().build()) {
99-
final HttpGet get1 = new HttpGet("/nostuff");
100-
httpclient.execute(target, get1, response -> {
101-
Assertions.assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode());
102-
EntityUtils.consume(response.getEntity());
103-
return null;
104-
});
105-
final HttpGet get2 = new HttpGet("/stuff");
106-
httpclient.execute(target, get2, response -> {
107-
Assertions.assertEquals(HttpStatus.SC_OK, response.getCode());
108-
EntityUtils.consume(response.getEntity());
109-
return null;
110-
});
111-
}
107+
.create();
108+
server.start();
109+
110+
final HttpHost target = new HttpHost("localhost", server.getLocalPort());
111+
try (final CloseableHttpClient httpclient = HttpClientBuilder.create().build()) {
112+
final HttpGet get1 = new HttpGet("/nostuff");
113+
httpclient.execute(target, get1, response -> {
114+
Assertions.assertEquals(HttpStatus.SC_NO_CONTENT, response.getCode());
115+
EntityUtils.consume(response.getEntity());
116+
return null;
117+
});
118+
final HttpGet get2 = new HttpGet("/stuff");
119+
httpclient.execute(target, get2, response -> {
120+
Assertions.assertEquals(HttpStatus.SC_OK, response.getCode());
121+
EntityUtils.consume(response.getEntity());
122+
return null;
123+
});
112124
}
113125
}
114126

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<properties>
6363
<maven.compiler.source>1.8</maven.compiler.source>
6464
<maven.compiler.target>1.8</maven.compiler.target>
65-
<httpcore.version>5.3-alpha2</httpcore.version>
65+
<httpcore.version>5.3-beta1</httpcore.version>
6666
<log4j.version>2.23.0</log4j.version>
6767
<brotli.version>0.1.2</brotli.version>
6868
<conscrypt.version>2.5.2</conscrypt.version>

0 commit comments

Comments
 (0)