use of org.apache.hc.core5.http.Method in project httpcomponents-core by apache.
the class TestDefaultH2RequestConverter method testConvertFromFieldsConnectPresentScheme.
@Test
public void testConvertFromFieldsConnectPresentScheme() throws Exception {
final List<Header> headers = Arrays.asList(new BasicHeader(":method", "CONNECT"), new BasicHeader(":scheme", "http"), new BasicHeader(":authority", "www.example.com"), new BasicHeader("custom", "value"));
final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
Assertions.assertThrows(HttpException.class, () -> converter.convert(headers), "Header ':scheme' must not be set for CONNECT request");
}
use of org.apache.hc.core5.http.Method in project httpcomponents-core by apache.
the class TestDefaultH2RequestConverter method testConvertFromFieldsConnect.
@Test
public void testConvertFromFieldsConnect() throws Exception {
final List<Header> headers = Arrays.asList(new BasicHeader(":method", "CONNECT"), new BasicHeader(":authority", "www.example.com"), new BasicHeader("custom", "value"));
final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
converter.convert(headers);
}
use of org.apache.hc.core5.http.Method in project httpcomponents-core by apache.
the class TestDefaultH2RequestConverter method testConvertFromMessageBasic.
@Test
public void testConvertFromMessageBasic() throws Exception {
final HttpRequest request = new BasicHttpRequest("GET", new HttpHost("host"), "/");
request.addHeader("custom123", "Value");
final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
final List<Header> headers = converter.convert(request);
Assertions.assertNotNull(headers);
Assertions.assertEquals(5, headers.size());
final Header header1 = headers.get(0);
Assertions.assertEquals(":method", header1.getName());
Assertions.assertEquals("GET", header1.getValue());
final Header header2 = headers.get(1);
Assertions.assertEquals(":scheme", header2.getName());
Assertions.assertEquals("http", header2.getValue());
final Header header3 = headers.get(2);
Assertions.assertEquals(":authority", header3.getName());
Assertions.assertEquals("host", header3.getValue());
final Header header4 = headers.get(3);
Assertions.assertEquals(":path", header4.getName());
Assertions.assertEquals("/", header4.getValue());
final Header header5 = headers.get(4);
Assertions.assertEquals("custom123", header5.getName());
Assertions.assertEquals("Value", header5.getValue());
}
use of org.apache.hc.core5.http.Method in project httpcomponents-core by apache.
the class TestDefaultH2RequestConverter method testConvertFromFieldsBasic.
@Test
public void testConvertFromFieldsBasic() throws Exception {
final List<Header> headers = Arrays.asList(new BasicHeader(":method", "GET"), new BasicHeader(":scheme", "http"), new BasicHeader(":authority", "www.example.com"), new BasicHeader(":path", "/"), new BasicHeader("custom123", "value"));
final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
final HttpRequest request = converter.convert(headers);
Assertions.assertNotNull(request);
Assertions.assertEquals("GET", request.getMethod());
Assertions.assertEquals("http", request.getScheme());
Assertions.assertEquals(new URIAuthority("www.example.com"), request.getAuthority());
Assertions.assertEquals("/", request.getPath());
final Header[] allHeaders = request.getHeaders();
Assertions.assertEquals(1, allHeaders.length);
Assertions.assertEquals("custom123", allHeaders[0].getName());
Assertions.assertEquals("value", allHeaders[0].getValue());
}
use of org.apache.hc.core5.http.Method in project httpcomponents-core by apache.
the class TestDefaultH2RequestConverter method testConvertFromFieldsUpperCaseHeaderName.
@Test
public void testConvertFromFieldsUpperCaseHeaderName() throws Exception {
final List<Header> headers = Arrays.asList(new BasicHeader(":method", "GET"), new BasicHeader(":scheme", "http"), new BasicHeader(":authority", "www.example.com"), new BasicHeader(":Path", "/"), new BasicHeader("custom", "value"));
final DefaultH2RequestConverter converter = new DefaultH2RequestConverter();
Assertions.assertThrows(HttpException.class, () -> converter.convert(headers), "Header name ':Path' is invalid (header name contains uppercase characters)");
}
Aggregations