Upgraded HttpCore to version 5.3-beta1
This commit is contained in:
parent
0b4b06d080
commit
0b4e653eda
|
@ -33,29 +33,37 @@ import org.apache.hc.client5.http.classic.methods.HttpGet;
|
||||||
import org.apache.hc.client5.http.cookie.BasicCookieStore;
|
import org.apache.hc.client5.http.cookie.BasicCookieStore;
|
||||||
import org.apache.hc.client5.http.cookie.Cookie;
|
import org.apache.hc.client5.http.cookie.Cookie;
|
||||||
import org.apache.hc.client5.http.cookie.CookieStore;
|
import org.apache.hc.client5.http.cookie.CookieStore;
|
||||||
|
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
|
||||||
|
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
|
||||||
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
import org.apache.hc.client5.http.protocol.HttpClientContext;
|
||||||
import org.apache.hc.client5.testing.extension.sync.ClientProtocolLevel;
|
|
||||||
import org.apache.hc.client5.testing.extension.sync.TestClient;
|
|
||||||
import org.apache.hc.core5.http.HttpHost;
|
import org.apache.hc.core5.http.HttpHost;
|
||||||
import org.apache.hc.core5.http.HttpStatus;
|
import org.apache.hc.core5.http.HttpStatus;
|
||||||
import org.apache.hc.core5.http.URIScheme;
|
import org.apache.hc.core5.http.impl.bootstrap.HttpServer;
|
||||||
|
import org.apache.hc.core5.http.impl.bootstrap.ServerBootstrap;
|
||||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||||
import org.apache.hc.core5.http.message.BasicHeader;
|
import org.apache.hc.core5.http.message.BasicHeader;
|
||||||
|
import org.apache.hc.core5.io.CloseMode;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class tests cookie matching when using Virtual Host.
|
* This class tests cookie matching when using Virtual Host.
|
||||||
*/
|
*/
|
||||||
public class TestCookieVirtualHost extends AbstractIntegrationTestBase {
|
public class TestCookieVirtualHost {
|
||||||
|
|
||||||
public TestCookieVirtualHost() {
|
private HttpServer server;
|
||||||
super(URIScheme.HTTP, ClientProtocolLevel.STANDARD);
|
|
||||||
|
@AfterEach
|
||||||
|
public void shutDown() throws Exception {
|
||||||
|
if (this.server != null) {
|
||||||
|
this.server.close(CloseMode.GRACEFUL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCookieMatchingWithVirtualHosts() throws Exception {
|
public void testCookieMatchingWithVirtualHosts() throws Exception {
|
||||||
configureServer(bootstrap -> bootstrap
|
server = ServerBootstrap.bootstrap()
|
||||||
.register("app.mydomain.fr", "*", (request, response, context) -> {
|
.register("app.mydomain.fr", "*", (request, response, context) -> {
|
||||||
|
|
||||||
final int n = Integer.parseInt(request.getFirstHeader("X-Request").getValue());
|
final int n = Integer.parseInt(request.getFirstHeader("X-Request").getValue());
|
||||||
|
@ -93,12 +101,12 @@ public class TestCookieVirtualHost extends AbstractIntegrationTestBase {
|
||||||
Assertions.fail("Unexpected value: " + n);
|
Assertions.fail("Unexpected value: " + n);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}));
|
})
|
||||||
|
.create();
|
||||||
final HttpHost target = startServer();
|
server.start();
|
||||||
|
|
||||||
final TestClient client = client();
|
|
||||||
|
|
||||||
|
final HttpHost target = new HttpHost("localhost", server.getLocalPort());
|
||||||
|
try (final CloseableHttpClient client = HttpClientBuilder.create().build()) {
|
||||||
final CookieStore cookieStore = new BasicCookieStore();
|
final CookieStore cookieStore = new BasicCookieStore();
|
||||||
final HttpClientContext context = HttpClientContext.create();
|
final HttpClientContext context = HttpClientContext.create();
|
||||||
context.setCookieStore(cookieStore);
|
context.setCookieStore(cookieStore);
|
||||||
|
@ -107,6 +115,7 @@ public class TestCookieVirtualHost extends AbstractIntegrationTestBase {
|
||||||
final HttpGet request1 = new HttpGet(new URI("http://app.mydomain.fr"));
|
final HttpGet request1 = new HttpGet(new URI("http://app.mydomain.fr"));
|
||||||
request1.addHeader("X-Request", "1");
|
request1.addHeader("X-Request", "1");
|
||||||
client.execute(target, request1, context, response -> {
|
client.execute(target, request1, context, response -> {
|
||||||
|
Assertions.assertEquals(200, response.getCode());
|
||||||
EntityUtils.consume(response.getEntity());
|
EntityUtils.consume(response.getEntity());
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
@ -121,6 +130,7 @@ public class TestCookieVirtualHost extends AbstractIntegrationTestBase {
|
||||||
final HttpGet request2 = new HttpGet(new URI("http://app.mydomain.fr"));
|
final HttpGet request2 = new HttpGet(new URI("http://app.mydomain.fr"));
|
||||||
request2.addHeader("X-Request", "2");
|
request2.addHeader("X-Request", "2");
|
||||||
client.execute(target, request2, context, response -> {
|
client.execute(target, request2, context, response -> {
|
||||||
|
Assertions.assertEquals(200, response.getCode());
|
||||||
EntityUtils.consume(response.getEntity());
|
EntityUtils.consume(response.getEntity());
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
|
@ -129,9 +139,11 @@ public class TestCookieVirtualHost extends AbstractIntegrationTestBase {
|
||||||
final HttpGet request3 = new HttpGet(new URI("http://app.mydomain.fr"));
|
final HttpGet request3 = new HttpGet(new URI("http://app.mydomain.fr"));
|
||||||
request3.addHeader("X-Request", "3");
|
request3.addHeader("X-Request", "3");
|
||||||
client.execute(target, request3, context, response -> {
|
client.execute(target, request3, context, response -> {
|
||||||
|
Assertions.assertEquals(200, response.getCode());
|
||||||
EntityUtils.consume(response.getEntity());
|
EntityUtils.consume(response.getEntity());
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,6 +100,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -129,6 +130,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -155,6 +157,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -185,6 +188,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
.setSslSetupHandler(sslParameters -> sslParameters.setNeedClientAuth(true))
|
.setSslSetupHandler(sslParameters -> sslParameters.setNeedClientAuth(true))
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -217,6 +221,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -250,6 +255,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -283,6 +289,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
.setSslSetupHandler(sslParameters -> sslParameters.setProtocols(new String[] {"SSLv3"}))
|
.setSslSetupHandler(sslParameters -> sslParameters.setProtocols(new String[] {"SSLv3"}))
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -335,6 +342,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
.setSslSetupHandler(sslParameters -> sslParameters.setProtocols(new String[] {cipherSuite}))
|
.setSslSetupHandler(sslParameters -> sslParameters.setProtocols(new String[] {cipherSuite}))
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -358,6 +366,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
@ -419,6 +428,7 @@ public class TestDefaultClientTlsStrategy {
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
this.server = ServerBootstrap.bootstrap()
|
this.server = ServerBootstrap.bootstrap()
|
||||||
.setSslContext(SSLTestContexts.createServerSSLContext())
|
.setSslContext(SSLTestContexts.createServerSSLContext())
|
||||||
|
.setRequestRouter((r, c) -> null)
|
||||||
.create();
|
.create();
|
||||||
// @formatter:on
|
// @formatter:on
|
||||||
this.server.start();
|
this.server.start();
|
||||||
|
|
|
@ -72,6 +72,7 @@ public class TestFutureRequestExecutionService {
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void before() throws Exception {
|
public void before() throws Exception {
|
||||||
this.localServer = ServerBootstrap.bootstrap()
|
this.localServer = ServerBootstrap.bootstrap()
|
||||||
|
.setCanonicalHostName("localhost")
|
||||||
.register("/wait", (request, response, context) -> {
|
.register("/wait", (request, response, context) -> {
|
||||||
try {
|
try {
|
||||||
while(blocked.get()) {
|
while(blocked.get()) {
|
||||||
|
|
|
@ -43,11 +43,22 @@ import org.apache.hc.core5.http.impl.io.DefaultBHttpServerConnection;
|
||||||
import org.apache.hc.core5.http.io.HttpConnectionFactory;
|
import org.apache.hc.core5.http.io.HttpConnectionFactory;
|
||||||
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
import org.apache.hc.core5.http.io.entity.EntityUtils;
|
||||||
import org.apache.hc.core5.http.io.entity.StringEntity;
|
import org.apache.hc.core5.http.io.entity.StringEntity;
|
||||||
|
import org.apache.hc.core5.io.CloseMode;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
public class TestMalformedServerResponse {
|
public class TestMalformedServerResponse {
|
||||||
|
|
||||||
|
private HttpServer server;
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void shutDown() throws Exception {
|
||||||
|
if (this.server != null) {
|
||||||
|
this.server.close(CloseMode.GRACEFUL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static class BrokenServerConnection extends DefaultBHttpServerConnection {
|
static class BrokenServerConnection extends DefaultBHttpServerConnection {
|
||||||
|
|
||||||
public BrokenServerConnection(final String scheme, final Http1Config h1Config) {
|
public BrokenServerConnection(final String scheme, final Http1Config h1Config) {
|
||||||
|
@ -85,15 +96,17 @@ public class TestMalformedServerResponse {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoContentResponseWithGarbage() throws Exception {
|
public void testNoContentResponseWithGarbage() throws Exception {
|
||||||
try (final HttpServer server = ServerBootstrap.bootstrap()
|
server = ServerBootstrap.bootstrap()
|
||||||
|
.setCanonicalHostName("localhost")
|
||||||
.setConnectionFactory(new BrokenServerConnectionFactory())
|
.setConnectionFactory(new BrokenServerConnectionFactory())
|
||||||
.register("/nostuff", (request, response, context) -> response.setCode(HttpStatus.SC_NO_CONTENT))
|
.register("/nostuff", (request, response, context) -> response.setCode(HttpStatus.SC_NO_CONTENT))
|
||||||
.register("/stuff", (request, response, context) -> {
|
.register("/stuff", (request, response, context) -> {
|
||||||
response.setCode(HttpStatus.SC_OK);
|
response.setCode(HttpStatus.SC_OK);
|
||||||
response.setEntity(new StringEntity("Some important stuff"));
|
response.setEntity(new StringEntity("Some important stuff"));
|
||||||
})
|
})
|
||||||
.create()) {
|
.create();
|
||||||
server.start();
|
server.start();
|
||||||
|
|
||||||
final HttpHost target = new HttpHost("localhost", server.getLocalPort());
|
final HttpHost target = new HttpHost("localhost", server.getLocalPort());
|
||||||
try (final CloseableHttpClient httpclient = HttpClientBuilder.create().build()) {
|
try (final CloseableHttpClient httpclient = HttpClientBuilder.create().build()) {
|
||||||
final HttpGet get1 = new HttpGet("/nostuff");
|
final HttpGet get1 = new HttpGet("/nostuff");
|
||||||
|
@ -110,6 +123,5 @@ public class TestMalformedServerResponse {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -62,7 +62,7 @@
|
||||||
<properties>
|
<properties>
|
||||||
<maven.compiler.source>1.8</maven.compiler.source>
|
<maven.compiler.source>1.8</maven.compiler.source>
|
||||||
<maven.compiler.target>1.8</maven.compiler.target>
|
<maven.compiler.target>1.8</maven.compiler.target>
|
||||||
<httpcore.version>5.3-alpha2</httpcore.version>
|
<httpcore.version>5.3-beta1</httpcore.version>
|
||||||
<log4j.version>2.23.0</log4j.version>
|
<log4j.version>2.23.0</log4j.version>
|
||||||
<brotli.version>0.1.2</brotli.version>
|
<brotli.version>0.1.2</brotli.version>
|
||||||
<conscrypt.version>2.5.2</conscrypt.version>
|
<conscrypt.version>2.5.2</conscrypt.version>
|
||||||
|
|
Loading…
Reference in New Issue