use of org.apache.hc.core5.http.protocol.RequestValidateHost in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestHttp11MultipleHostHeaders.
@Test
public void testRequestHttp11MultipleHostHeaders() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
request.addHeader(HttpHeaders.HOST, "blah");
request.addHeader(HttpHeaders.HOST, "blah");
final RequestValidateHost interceptor = new RequestValidateHost();
Assertions.assertThrows(ProtocolException.class, () -> interceptor.process(request, request.getEntity(), context));
}
use of org.apache.hc.core5.http.protocol.RequestValidateHost in project httpcomponents-core by apache.
the class TestStandardInterceptors method testRequestHttp10HostHeaderAbsent.
@Test
public void testRequestHttp10HostHeaderAbsent() throws Exception {
final HttpContext context = new BasicHttpContext(null);
final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
request.setVersion(HttpVersion.HTTP_1_0);
final RequestValidateHost interceptor = new RequestValidateHost();
interceptor.process(request, request.getEntity(), context);
}
use of org.apache.hc.core5.http.protocol.RequestValidateHost in project httpcomponents-core by apache.
the class JSSEProviderIntegrationTest method testSimpleGetIdentityTransfer.
@Test
public void testSimpleGetIdentityTransfer() throws Exception {
server.register("/hello", () -> new SingleLineResponseHandler("Hi there"));
final HttpProcessor httpProcessor = new DefaultHttpProcessor(new RequestValidateHost());
final InetSocketAddress serverEndpoint = server.start(httpProcessor, Http1Config.DEFAULT);
client.start();
for (int i = 0; i < REQ_NUM; i++) {
final Future<ClientSessionEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), TIMEOUT);
try (final ClientSessionEndpoint streamEndpoint = connectFuture.get()) {
final Future<Message<HttpResponse, String>> future = streamEndpoint.execute(new BasicRequestProducer(Method.GET, createRequestURI(serverEndpoint, "/hello")), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
final Message<HttpResponse, String> result = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
Assertions.assertNotNull(result);
final HttpResponse response = result.getHead();
final String entity = result.getBody();
Assertions.assertNotNull(response);
Assertions.assertEquals(200, response.getCode());
Assertions.assertEquals("Hi there", entity);
}
}
}
use of org.apache.hc.core5.http.protocol.RequestValidateHost in project httpcomponents-core by apache.
the class Http1IntegrationTest method testSimpleGetIdentityTransfer.
@Test
public void testSimpleGetIdentityTransfer() throws Exception {
server.register("/hello", () -> new SingleLineResponseHandler("Hi there"));
final HttpProcessor httpProcessor = new DefaultHttpProcessor(new RequestValidateHost());
final InetSocketAddress serverEndpoint = server.start(httpProcessor, Http1Config.DEFAULT);
client.start();
final int reqNo = 5;
for (int i = 0; i < reqNo; i++) {
final Future<ClientSessionEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), TIMEOUT);
final ClientSessionEndpoint streamEndpoint = connectFuture.get();
final Future<Message<HttpResponse, String>> future = streamEndpoint.execute(new BasicRequestProducer(Method.GET, createRequestURI(serverEndpoint, "/hello")), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
final Message<HttpResponse, String> result = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
streamEndpoint.close();
Assertions.assertNotNull(result);
final HttpResponse response = result.getHead();
final String entity = result.getBody();
Assertions.assertNotNull(response);
Assertions.assertEquals(200, response.getCode());
Assertions.assertEquals("Hi there", entity);
}
}
use of org.apache.hc.core5.http.protocol.RequestValidateHost in project httpcomponents-core by apache.
the class Http1IntegrationTest method testPostIdentityTransfer.
@Test
public void testPostIdentityTransfer() throws Exception {
server.register("/hello", () -> new SingleLineResponseHandler("Hi there"));
final HttpProcessor httpProcessor = new DefaultHttpProcessor(new RequestValidateHost());
final InetSocketAddress serverEndpoint = server.start(httpProcessor, Http1Config.DEFAULT);
client.start();
final int reqNo = 5;
for (int i = 0; i < reqNo; i++) {
final Future<ClientSessionEndpoint> connectFuture = client.connect("localhost", serverEndpoint.getPort(), TIMEOUT);
final ClientSessionEndpoint streamEndpoint = connectFuture.get();
final Future<Message<HttpResponse, String>> future = streamEndpoint.execute(new BasicRequestProducer(Method.POST, createRequestURI(serverEndpoint, "/hello"), new MultiLineEntityProducer("Hello", 16 * i)), new BasicResponseConsumer<>(new StringAsyncEntityConsumer()), null);
final Message<HttpResponse, String> result = future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
streamEndpoint.close();
Assertions.assertNotNull(result);
final HttpResponse response = result.getHead();
final String entity = result.getBody();
Assertions.assertNotNull(response);
Assertions.assertEquals(200, response.getCode());
Assertions.assertEquals("Hi there", entity);
}
}
Aggregations