Search in sources :

Example 26 with BasicHttpRequest

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

the class TestBasicMessages method testRequestWithAuthority.

@Test
public void testRequestWithAuthority() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, new HttpHost("http", "somehost", -1), "/stuff");
    Assertions.assertEquals(Method.GET.name(), request.getMethod());
    Assertions.assertEquals("/stuff", request.getPath());
    Assertions.assertEquals(new URIAuthority("somehost"), request.getAuthority());
    Assertions.assertEquals(new URI("http://somehost/stuff"), request.getUri());
}
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 27 with BasicHttpRequest

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

the class TestBasicMessages method testRequestWithRelativeURI.

@Test
public void testRequestWithRelativeURI() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, new URI("/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 28 with BasicHttpRequest

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

the class TestBasicMessages method testRequestWithAuthorityRelativePath.

@Test
public void testRequestWithAuthorityRelativePath() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, new HttpHost("http", "somehost", -1), "stuff");
    Assertions.assertEquals(Method.GET.name(), request.getMethod());
    Assertions.assertEquals("stuff", request.getPath());
    Assertions.assertEquals(new URIAuthority("somehost"), request.getAuthority());
    Assertions.assertEquals(new URI("http://somehost/stuff"), request.getUri());
}
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 29 with BasicHttpRequest

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

the class TestBasicMessages method testRequestWithUserInfo.

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

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

the class TestBasicMessages method testRequestWithAbsoluteURIAsPath.

@Test
public void testRequestWithAbsoluteURIAsPath() throws Exception {
    final HttpRequest request = new BasicHttpRequest(Method.GET, "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)

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