Search in sources :

Example 1 with UrlInfo

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());
}
Also used : UrlInfo(org.webpieces.httpparser.api.dto.UrlInfo) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) Test(org.junit.Test)

Example 2 with UrlInfo

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;
}
Also used : UrlInfo(org.webpieces.httpparser.api.dto.UrlInfo) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) LinkedList(java.util.LinkedList)

Example 3 with UrlInfo

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());
}
Also used : UrlInfo(org.webpieces.httpparser.api.dto.UrlInfo) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) Test(org.junit.Test)

Aggregations

UrlInfo (org.webpieces.httpparser.api.dto.UrlInfo)3 Test (org.junit.Test)2 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)2 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)1 LinkedList (java.util.LinkedList)1 Header (org.webpieces.httpparser.api.common.Header)1 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)1