Search in sources :

Example 21 with Http2Header

use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.

the class Requests method createTrailers.

public static Http2Trailers createTrailers() {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.ACCEPT, "*/*"));
    headers.add(new Http2Header(Http2HeaderName.ACCEPT_ENCODING, "gzip, deflate"));
    headers.add(new Http2Header(Http2HeaderName.USER_AGENT, "webpieces/1.15.0"));
    Http2Trailers trailers = new Http2Trailers(headers);
    return trailers;
}
Also used : Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers)

Example 22 with Http2Header

use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.

the class Requests method createPush.

public static Http2Push createPush(int streamId) {
    Http2Push push = new Http2Push();
    push.setStreamId(streamId);
    push.setPromisedStreamId(2);
    push.addHeader(new Http2Header(Http2HeaderName.SERVER, "me"));
    return push;
}
Also used : Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Push(com.webpieces.hpack.api.dto.Http2Push)

Example 23 with Http2Header

use of com.webpieces.http2parser.api.dto.lib.Http2Header 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)

Example 24 with Http2Header

use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.

the class Responses method createResponse.

public static Http2Response createResponse(int id) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.SERVER, "id"));
    headers.add(new Http2Header(Http2HeaderName.STATUS, "200"));
    headers.add(new Http2Header(Http2HeaderName.CONTENT_LENGTH, "0"));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(true);
    return response;
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 25 with Http2Header

use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.

the class Http2Translations method insertInfo.

private static void insertInfo(HttpRequest req, Http2Header header) {
    if (headersToSkip.contains(header.getName()))
        return;
    if (header.getKnownName() == Http2HeaderName.AUTHORITY) {
        //this keeps header order which is sometimes important
        req.addHeader(new Header(KnownHeaderName.HOST, header.getValue()));
        return;
    }
    String name = translateName(header.getName());
    req.addHeader(new Header(name, header.getValue()));
}
Also used : Header(org.webpieces.httpparser.api.common.Header) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header)

Aggregations

Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)36 ArrayList (java.util.ArrayList)16 Http2Response (com.webpieces.hpack.api.dto.Http2Response)13 Http2Request (com.webpieces.hpack.api.dto.Http2Request)6 Http2HeaderName (com.webpieces.http2parser.api.dto.lib.Http2HeaderName)6 Http2Push (com.webpieces.hpack.api.dto.Http2Push)5 StreamWriter (com.webpieces.http2engine.api.StreamWriter)4 Http2Frame (com.webpieces.http2parser.api.dto.lib.Http2Frame)4 CompletableFuture (java.util.concurrent.CompletableFuture)4 Header (org.webpieces.httpparser.api.common.Header)4 Logger (org.webpieces.util.logging.Logger)4 LoggerFactory (org.webpieces.util.logging.LoggerFactory)4 List (java.util.List)3 BufferPool (org.webpieces.data.api.BufferPool)3 Encoder (com.twitter.hpack.Encoder)2 Http2Headers (com.webpieces.hpack.api.dto.Http2Headers)2 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)2 HeaderEncoding (com.webpieces.hpack.impl.HeaderEncoding)2 PushPromiseListener (com.webpieces.http2engine.api.PushPromiseListener)2 PushStreamHandle (com.webpieces.http2engine.api.PushStreamHandle)2