use of org.webpieces.httpparser.api.dto.UrlInfo in project webpieces by deanhiller.
the class TestUriParsing method testSlash.
@Test
public void testSlash() {
HttpUri uri = new HttpUri("/");
UrlInfo urlInfo = uri.getUriBreakdown();
Assert.assertEquals(null, urlInfo.getPrefix());
Assert.assertEquals(null, urlInfo.getHost());
Assert.assertEquals(null, urlInfo.getPort());
Assert.assertEquals("/", urlInfo.getFullPath());
}
use of org.webpieces.httpparser.api.dto.UrlInfo in project webpieces by deanhiller.
the class Http2Translations method requestToHeaders.
private static Http2Request requestToHeaders(HttpRequest request, boolean fromSslChannel) {
HttpRequestLine requestLine = request.getRequestLine();
List<Header> requestHeaders = request.getHeaders();
LinkedList<Http2Header> headerList = new LinkedList<>();
// add special headers
headerList.add(new Http2Header(":method", requestLine.getMethod().getMethodAsString()));
UrlInfo urlInfo = requestLine.getUri().getUriBreakdown();
headerList.add(new Http2Header(":path", urlInfo.getFullPath()));
// Figure out scheme
if (urlInfo.getPrefix() != null) {
headerList.add(new Http2Header(":scheme", urlInfo.getPrefix()));
} else if (fromSslChannel) {
headerList.add(new Http2Header(":scheme", "https"));
} else {
headerList.add(new Http2Header(":scheme", "http"));
}
// Figure out authority
Header hostHeader = request.getHeaderLookupStruct().getHeader(KnownHeaderName.HOST);
if (hostHeader == null)
throw new IllegalArgumentException("Host header is required in http1.1");
// Add regular headers
for (Header header : requestHeaders) {
if (header.getKnownName() == KnownHeaderName.HOST) {
//keeps headers in order of http1 headers
String h = hostHeader.getValue();
headerList.add(new Http2Header(":authority", h));
continue;
}
headerList.add(new Http2Header(header.getName().toLowerCase(), header.getValue()));
}
Http2Request headers = new Http2Request(headerList);
Header contentLen = request.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
if (request.isHasChunkedTransferHeader()) {
headers.setEndOfStream(false);
} else if (contentLenGreaterThanZero(contentLen)) {
headers.setEndOfStream(false);
} else
headers.setEndOfStream(true);
return headers;
}
use of org.webpieces.httpparser.api.dto.UrlInfo in project webpieces by deanhiller.
the class TestUriParsing method testBasicUrl.
@Test
public void testBasicUrl() {
HttpUri uri = new HttpUri("http://www.google.com:8080/there/is/cool?at=this&some=that");
UrlInfo urlInfo = uri.getUriBreakdown();
Assert.assertEquals("http", urlInfo.getPrefix());
Assert.assertEquals("www.google.com", urlInfo.getHost());
Assert.assertEquals(new Integer(8080), urlInfo.getPort());
Assert.assertEquals("/there/is/cool?at=this&some=that", urlInfo.getFullPath());
}
Aggregations