Search in sources :

Example 21 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class HttpRequestWrapperTest method testRequestHostWithReservedChars.

@Test
public void testRequestHostWithReservedChars() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, URI.create("http://someuser%21@%21example%21.com/stuff"));
    final HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(request);
    Assertions.assertEquals(Method.GET.name(), httpRequestWrapper.getMethod());
    Assertions.assertEquals("/stuff", httpRequestWrapper.getPath());
    Assertions.assertEquals(new URIAuthority("someuser%21", "%21example%21.com", -1), httpRequestWrapper.getAuthority());
    Assertions.assertEquals(new URI("http://%21example%21.com/stuff"), httpRequestWrapper.getUri());
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) URIAuthority(org.apache.hc.core5.net.URIAuthority) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 22 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class HttpRequestWrapperTest method testRequestWithAuthority.

@Test
public void testRequestWithAuthority() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, new HttpHost("http", "somehost", -1), "/stuff");
    final HttpRequestWrapper httpRequestWrapper = new HttpRequestWrapper(request);
    Assertions.assertEquals(Method.GET.name(), httpRequestWrapper.getMethod());
    Assertions.assertEquals("/stuff", httpRequestWrapper.getPath());
    Assertions.assertEquals(new URIAuthority("somehost"), httpRequestWrapper.getAuthority());
    Assertions.assertEquals(new URI("http://somehost/stuff"), httpRequestWrapper.getUri());
    httpRequestWrapper.setAuthority(new URIAuthority("newHost"));
    Assertions.assertEquals(new URIAuthority("newHost"), httpRequestWrapper.getAuthority());
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) URIAuthority(org.apache.hc.core5.net.URIAuthority) HttpHost(org.apache.hc.core5.http.HttpHost) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 23 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class TestRequestHandlerRegistry method testResolveByLocalhostAndRequestUri.

@Test
public void testResolveByLocalhostAndRequestUri() throws Exception {
    handlerRegistry.register("myhost", "/test*", "stuff");
    Assertions.assertEquals("stuff", handlerRegistry.resolve(new BasicHttpRequest(Method.GET, new HttpHost("localhost"), "/test"), context));
    Assertions.assertEquals("stuff", handlerRegistry.resolve(new BasicHttpRequest(Method.GET, new HttpHost("LocalHost"), "/testabc"), context));
    Assertions.assertEquals("stuff", handlerRegistry.resolve(new BasicHttpRequest(Method.GET, new HttpHost("127.0.0.1"), "/testabc"), context));
}
Also used : HttpHost(org.apache.hc.core5.http.HttpHost) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 24 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class TestRequestHandlerRegistry method testResolveByUnknownHostname.

@Test
public void testResolveByUnknownHostname() throws Exception {
    handlerRegistry.register("myhost", "/test*", "stuff");
    Assertions.assertThrows(MisdirectedRequestException.class, () -> handlerRegistry.resolve(new BasicHttpRequest(Method.GET, new HttpHost("otherhost"), "/test"), context));
}
Also used : HttpHost(org.apache.hc.core5.http.HttpHost) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 25 with BasicHttpRequest

use of org.apache.hc.core5.http.message.BasicHttpRequest in project httpcomponents-core by apache.

the class TestBasicMessages method testDefaultRequestConstructors.

@Test
public void testDefaultRequestConstructors() {
    final HttpRequest request1 = new BasicHttpRequest("WHATEVER", "/");
    Assertions.assertEquals("WHATEVER", request1.getMethod());
    Assertions.assertEquals("/", request1.getPath());
    final HttpRequest request2 = new BasicHttpRequest(Method.GET, "/");
    Assertions.assertEquals(Method.GET.name(), request2.getMethod());
    Assertions.assertEquals("/", request2.getPath());
    Assertions.assertThrows(NullPointerException.class, () -> new BasicHttpRequest(Method.GET, (URI) null));
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Aggregations

HttpRequest (org.apache.hc.core5.http.HttpRequest)75 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)68 Test (org.junit.jupiter.api.Test)47 HttpResponse (org.apache.hc.core5.http.HttpResponse)41 BasicRequestProducer (org.apache.hc.core5.http.nio.support.BasicRequestProducer)37 Message (org.apache.hc.core5.http.Message)34 StringAsyncEntityConsumer (org.apache.hc.core5.http.nio.entity.StringAsyncEntityConsumer)33 InetSocketAddress (java.net.InetSocketAddress)30 HttpHost (org.apache.hc.core5.http.HttpHost)30 Test (org.junit.Test)30 URI (java.net.URI)23 HttpException (org.apache.hc.core5.http.HttpException)21 IOException (java.io.IOException)20 BasicHttpResponse (org.apache.hc.core5.http.message.BasicHttpResponse)19 URIAuthority (org.apache.hc.core5.net.URIAuthority)17 InterruptedIOException (java.io.InterruptedIOException)16 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)15 Header (org.apache.hc.core5.http.Header)14 URISyntaxException (java.net.URISyntaxException)8 ContentType (org.apache.hc.core5.http.ContentType)8