Search in sources :

Example 1 with HttpRequestLine

use of org.webpieces.httpparser.api.dto.HttpRequestLine in project webpieces by deanhiller.

the class HttpParserImpl method parseRequest.

private HttpMessage parseRequest(MementoImpl memento, List<String> lines) {
    //remove first line...
    String firstLine = lines.remove(0);
    String[] firstLinePieces = firstLine.split("\\s+");
    if (firstLinePieces.length != 3) {
        throw new ParseException("Unable to parse invalid http request due to first line being invalid=" + firstLine + " all Lines=" + lines);
    }
    HttpRequestMethod method = new HttpRequestMethod(firstLinePieces[0]);
    HttpUri uri = new HttpUri(firstLinePieces[1]);
    HttpVersion version = parseVersion(firstLinePieces[2], firstLine);
    HttpRequestLine httpRequestLine = new HttpRequestLine();
    httpRequestLine.setMethod(method);
    httpRequestLine.setUri(uri);
    httpRequestLine.setVersion(version);
    HttpRequest request = new HttpRequest();
    request.setRequestLine(httpRequestLine);
    parseHeaders(lines, request);
    memento.addMessage(request);
    return request;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestMethod(org.webpieces.httpparser.api.dto.HttpRequestMethod) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) ParseException(org.webpieces.httpparser.api.ParseException) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) HttpVersion(org.webpieces.httpparser.api.dto.HttpVersion)

Example 2 with HttpRequestLine

use of org.webpieces.httpparser.api.dto.HttpRequestLine in project webpieces by deanhiller.

the class IntegColoradoEdu method createRequest.

private static HttpRequest createRequest(String host) {
    //		GET / HTTP/1.1
    //		Host: www.colorado.edu
    //		User-Agent: curl/7.43.0
    //		Accept: */*
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.GET);
    requestLine.setUri(new HttpUri("/"));
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, host));
    req.addHeader(new Header(KnownHeaderName.ACCEPT, "*/*"));
    req.addHeader(new Header(KnownHeaderName.USER_AGENT, "webpieces/0.9"));
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Example 3 with HttpRequestLine

use of org.webpieces.httpparser.api.dto.HttpRequestLine in project webpieces by deanhiller.

the class TestLesson1BasicRequestResponse method createRequest.

static HttpRequest createRequest(String uri) {
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(KnownHttpMethod.GET);
    requestLine.setUri(new HttpUri(uri));
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, "yourdomain.com"));
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Example 4 with HttpRequestLine

use of org.webpieces.httpparser.api.dto.HttpRequestLine in project webpieces by deanhiller.

the class Requests method createRequest.

public static HttpRequest createRequest(KnownHttpMethod method, String url, boolean isHttps) {
    HttpUri httpUri = new HttpUri(url);
    HttpRequestLine requestLine = new HttpRequestLine();
    requestLine.setMethod(method);
    requestLine.setUri(httpUri);
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    req.addHeader(new Header(KnownHeaderName.HOST, "myhost.com"));
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Example 5 with HttpRequestLine

use of org.webpieces.httpparser.api.dto.HttpRequestLine 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)

Aggregations

HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)13 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)12 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)12 Header (org.webpieces.httpparser.api.common.Header)10 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)4 DataWrapper (org.webpieces.data.api.DataWrapper)3 HttpData (org.webpieces.httpparser.api.dto.HttpData)3 HttpRequestMethod (org.webpieces.httpparser.api.dto.HttpRequestMethod)2 Http2HeaderStruct (com.webpieces.hpack.api.dto.Http2HeaderStruct)1 Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Executor (java.util.concurrent.Executor)1 Executors (java.util.concurrent.Executors)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)1 BufferPool (org.webpieces.data.api.BufferPool)1