Search in sources :

Example 11 with URIAuthority

use of org.apache.hc.core5.net.URIAuthority in project httpcomponents-core by apache.

the class TestStandardInterceptors method testRequestTargetHostConnectHttp10.

@Test
public void testRequestTargetHostConnectHttp10() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    context.setProtocolVersion(HttpVersion.HTTP_1_0);
    final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.CONNECT, "/");
    request.setAuthority(new URIAuthority("somehost", 8080));
    final HttpRequestInterceptor interceptor = RequestTargetHost.INSTANCE;
    interceptor.process(request, request.getEntity(), context);
    final Header header = request.getFirstHeader(HttpHeaders.HOST);
    Assertions.assertNull(header);
}
Also used : URIAuthority(org.apache.hc.core5.net.URIAuthority) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) Header(org.apache.hc.core5.http.Header) BasicHeader(org.apache.hc.core5.http.message.BasicHeader) HttpRequestInterceptor(org.apache.hc.core5.http.HttpRequestInterceptor) Test(org.junit.jupiter.api.Test)

Example 12 with URIAuthority

use of org.apache.hc.core5.net.URIAuthority 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 13 with URIAuthority

use of org.apache.hc.core5.net.URIAuthority 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 14 with URIAuthority

use of org.apache.hc.core5.net.URIAuthority 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 15 with URIAuthority

use of org.apache.hc.core5.net.URIAuthority 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

URIAuthority (org.apache.hc.core5.net.URIAuthority)63 Test (org.junit.jupiter.api.Test)32 HttpRequest (org.apache.hc.core5.http.HttpRequest)21 HttpHost (org.apache.hc.core5.http.HttpHost)17 Header (org.apache.hc.core5.http.Header)15 URI (java.net.URI)14 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)11 HttpClientContext (org.apache.hc.client5.http.protocol.HttpClientContext)10 HttpException (org.apache.hc.core5.http.HttpException)9 IOException (java.io.IOException)8 ClassicHttpResponse (org.apache.hc.core5.http.ClassicHttpResponse)8 ProtocolException (org.apache.hc.core5.http.ProtocolException)8 HttpResponse (org.apache.hc.core5.http.HttpResponse)7 BasicClassicHttpResponse (org.apache.hc.core5.http.message.BasicClassicHttpResponse)7 HttpEntity (org.apache.hc.core5.http.HttpEntity)6 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)6 HttpContext (org.apache.hc.core5.http.protocol.HttpContext)6 HttpRoute (org.apache.hc.client5.http.HttpRoute)5 SimpleHttpResponse (org.apache.hc.client5.http.async.methods.SimpleHttpResponse)5 BasicClassicHttpRequest (org.apache.hc.core5.http.message.BasicClassicHttpRequest)5