Search in sources :

Example 1 with Http2HeaderStruct

use of com.webpieces.hpack.api.dto.Http2HeaderStruct in project webpieces by deanhiller.

the class Http2Translations method translateRequest.

public static HttpRequest translateRequest(Http2Request headers) {
    HttpRequestLine requestLine = new HttpRequestLine();
    HttpRequest req = new HttpRequest();
    req.setRequestLine(requestLine);
    for (Http2Header header : headers.getHeaders()) {
        insertInfo(req, header);
    }
    Http2HeaderStruct headerMap = headers.getHeaderLookupStruct();
    Http2Header method = headerMap.getHeader(Http2HeaderName.METHOD);
    if (method == null)
        throw new IllegalArgumentException(Http2HeaderName.METHOD.name() + "is a required header to translate to http1");
    req.getRequestLine().setMethod(new HttpRequestMethod(method.getValue()));
    Http2Header host = headerMap.getHeader(Http2HeaderName.AUTHORITY);
    if (host == null)
        throw new IllegalArgumentException(Http2HeaderName.AUTHORITY.name() + "is a required header to translate to http1");
    Http2Header path = headerMap.getHeader(Http2HeaderName.PATH);
    if (path == null)
        throw new IllegalArgumentException(Http2HeaderName.PATH.name() + "is a required header to translate to http1");
    HttpUri httpUri = new HttpUri(path.getValue());
    req.getRequestLine().setUri(httpUri);
    return req;
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestMethod(org.webpieces.httpparser.api.dto.HttpRequestMethod) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) Http2HeaderStruct(com.webpieces.hpack.api.dto.Http2HeaderStruct)

Aggregations

Http2HeaderStruct (com.webpieces.hpack.api.dto.Http2HeaderStruct)1 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)1 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)1 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)1 HttpRequestMethod (org.webpieces.httpparser.api.dto.HttpRequestMethod)1 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)1