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());
}
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());
}
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));
}
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));
}
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));
}
Aggregations