Search in sources :

Example 6 with URIAuthority

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

the class HttpRequestWrapperTest method testRequestWithAbsoluteURIAsPath.

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

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

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

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

the class TestStandardInterceptors method testRequestHttpHostHeaderNoPort.

@Test
public void testRequestHttpHostHeaderNoPort() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
    request.setVersion(HttpVersion.HTTP_1_1);
    request.setHeader(HttpHeaders.HOST, "host");
    final RequestValidateHost interceptor = new RequestValidateHost();
    interceptor.process(request, request.getEntity(), context);
    Assertions.assertEquals(new URIAuthority("host"), request.getAuthority());
}
Also used : URIAuthority(org.apache.hc.core5.net.URIAuthority) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 10 with URIAuthority

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

the class TestStandardInterceptors method testRequestHttpHostHeader.

@Test
public void testRequestHttpHostHeader() throws Exception {
    final HttpContext context = new BasicHttpContext(null);
    final BasicClassicHttpRequest request = new BasicClassicHttpRequest(Method.GET, "/");
    request.setVersion(HttpVersion.HTTP_1_1);
    request.setHeader(HttpHeaders.HOST, "host:8888");
    final RequestValidateHost interceptor = new RequestValidateHost();
    interceptor.process(request, request.getEntity(), context);
    Assertions.assertEquals(new URIAuthority("host", 8888), request.getAuthority());
}
Also used : URIAuthority(org.apache.hc.core5.net.URIAuthority) BasicClassicHttpRequest(org.apache.hc.core5.http.message.BasicClassicHttpRequest) 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