Search in sources :

Example 66 with BasicHttpRequest

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

the class TestBasicMessages method testRequestAbsoluteRequestUri.

@Test
public void testRequestAbsoluteRequestUri() throws Exception {
    final BasicHttpRequest request = new BasicHttpRequest(Method.GET, new HttpHost("http", "somehost", -1), "stuff");
    Assertions.assertEquals("stuff", request.getRequestUri());
    request.setAbsoluteRequestUri(true);
    Assertions.assertEquals("http://somehost/stuff", request.getRequestUri());
}
Also used : HttpHost(org.apache.hc.core5.http.HttpHost) Test(org.junit.jupiter.api.Test)

Example 67 with BasicHttpRequest

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

the class TestBasicMessages method testRequestWithAbsoluteURI.

@Test
public void testRequestWithAbsoluteURI() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, new URI("https://host:9443/stuff?param=value"));
    Assertions.assertEquals(Method.GET.name(), request.getMethod());
    Assertions.assertEquals("/stuff?param=value", request.getPath());
    Assertions.assertEquals(new URIAuthority("host", 9443), request.getAuthority());
    Assertions.assertEquals("https", request.getScheme());
    Assertions.assertEquals(new URI("https://host:9443/stuff?param=value"), request.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 68 with BasicHttpRequest

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

the class TestBasicMessages method testRequestHostWithReservedChars.

@Test
public void testRequestHostWithReservedChars() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, URI.create("http://someuser%21@%21example%21.com/stuff"));
    Assertions.assertEquals(Method.GET.name(), request.getMethod());
    Assertions.assertEquals("/stuff", request.getPath());
    Assertions.assertEquals(new URIAuthority("someuser%21", "%21example%21.com", -1), request.getAuthority());
    Assertions.assertEquals(new URI("http://%21example%21.com/stuff"), request.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 69 with BasicHttpRequest

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

the class TestBasicMessages method testRequestBasics.

@Test
public void testRequestBasics() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, "/stuff");
    Assertions.assertEquals(Method.GET.name(), request.getMethod());
    Assertions.assertEquals("/stuff", request.getPath());
    Assertions.assertNull(request.getAuthority());
    Assertions.assertEquals(new URI("/stuff"), request.getUri());
}
Also used : HttpRequest(org.apache.hc.core5.http.HttpRequest) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 70 with BasicHttpRequest

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

the class TestRequestHandlerRegistry method testResolveByHostnameAndRequestUri.

@Test
public void testResolveByHostnameAndRequestUri() throws Exception {
    handlerRegistry.register("myhost", "/test*", "stuff");
    Assertions.assertEquals("stuff", handlerRegistry.resolve(new BasicHttpRequest(Method.GET, new HttpHost("myhost"), "/test"), context));
    Assertions.assertEquals("stuff", handlerRegistry.resolve(new BasicHttpRequest(Method.GET, new HttpHost("MyHost"), "/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)

Aggregations

HttpRequest (org.apache.hc.core5.http.HttpRequest)75 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)68 Test (org.junit.jupiter.api.Test)45 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