Search in sources :

Example 76 with BasicHttpRequest

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

the class TestDefaultH2RequestConverter method testConvertFromMessageMissingScheme.

@Test
public void testConvertFromMessageMissingScheme() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", new HttpHost("host"), "/");
    request.addHeader("Custom123", "Value");
    request.setScheme(null);
    final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
    Assertions.assertThrows(HttpException.class, () -> converter.convert(request), "Request scheme is not set");
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) HttpHost(org.apache.hc.core5.http.HttpHost) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 77 with BasicHttpRequest

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

the class TestDefaultH2RequestConverter method testConvertFromMessageConnectWithPath.

@Test
public void testConvertFromMessageConnectWithPath() throws Exception {
    final HttpRequest request = new BasicHttpRequest("CONNECT", "/");
    request.setAuthority(new URIAuthority("host"));
    request.addHeader("Custom123", "Value");
    final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
    Assertions.assertThrows(HttpException.class, () -> converter.convert(request), "CONNECT request path must be null");
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) URIAuthority(org.apache.hc.core5.net.URIAuthority) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 78 with BasicHttpRequest

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

the class TestDefaultH2RequestConverter method testConvertFromFieldsProxyConnectionHeader.

@Test
public void testConvertFromFieldsProxyConnectionHeader() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", new HttpHost("host"), "/");
    request.addHeader("Proxy-Connection", "keep-alive");
    final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
    Assertions.assertThrows(HttpException.class, () -> converter.convert(request), "Header 'Proxy-Connection: Keep-Alive' is illegal for HTTP/2 messages");
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) HttpHost(org.apache.hc.core5.http.HttpHost) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 79 with BasicHttpRequest

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

the class TestDefaultH2RequestConverter method testConvertFromFieldsHostHeader.

@Test
public void testConvertFromFieldsHostHeader() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", new HttpHost("host"), "/");
    request.addHeader("Host", "host");
    final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
    Assertions.assertThrows(HttpException.class, () -> converter.convert(request), "Header 'Host: host' is illegal for HTTP/2 messages");
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) HttpHost(org.apache.hc.core5.http.HttpHost) BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) Test(org.junit.jupiter.api.Test)

Example 80 with BasicHttpRequest

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

the class TestDefaultH2RequestConverter method testConvertFromFieldsUpgradeHeader.

@Test
public void testConvertFromFieldsUpgradeHeader() throws Exception {
    final HttpRequest request = new BasicHttpRequest("GET", new HttpHost("host"), "/");
    request.addHeader("Upgrade", "example/1, foo/2");
    final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
    Assertions.assertThrows(HttpException.class, () -> converter.convert(request), "Header 'Upgrade: example/1, foo/2' is illegal for HTTP/2 messages");
}
Also used : BasicHttpRequest(org.apache.hc.core5.http.message.BasicHttpRequest) HttpRequest(org.apache.hc.core5.http.HttpRequest) 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