Search in sources :

Example 11 with Http2Header

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

the class Http2Requests method createPush.

public static Http2Push createPush(int streamId) {
    Http2Push push = new Http2Push();
    push.setStreamId(streamId);
    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 12 with Http2Header

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

the class TestS4FrameSizeAndHeaders method fillHeaders.

private void fillHeaders(Http2Response response1) {
    String value = "heaheaheaheaheaheahahoz.zhxheh,h,he,he,heaheaeaheaheahoahoahozzoqorqzro.zo.zrszaroatroathoathoathoathoatoh";
    for (int i = 0; i < 10; i++) {
        value = value + value;
        response1.addHeader(new Http2Header("eaheahaheaheaeha" + i, value));
    }
}
Also used : Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header)

Example 13 with Http2Header

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

the class TestS4FrameSizeAndHeaders method createInterleavedFrames.

private List<Http2Frame> createInterleavedFrames() {
    Http2Response response1 = new Http2Response();
    response1.setStreamId(1);
    response1.setEndOfStream(true);
    fillHeaders(response1);
    HeaderEncoding encoding = new HeaderEncoding();
    List<Http2Frame> frames1 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response1);
    Http2Response response2 = new Http2Response();
    response2.setStreamId(3);
    response1.setEndOfStream(true);
    response2.addHeader(new Http2Header(Http2HeaderName.ACCEPT, "value"));
    List<Http2Frame> frames2 = encoding.translateToFrames(localSettings.getMaxFrameSize(), new Encoder(localSettings.getHeaderTableSize()), response2);
    List<Http2Frame> frames = new ArrayList<>();
    frames.addAll(frames1);
    frames.add(1, frames2.get(0));
    return frames;
}
Also used : Http2Response(com.webpieces.hpack.api.dto.Http2Response) HeaderEncoding(com.webpieces.hpack.impl.HeaderEncoding) Encoder(com.twitter.hpack.Encoder) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) ArrayList(java.util.ArrayList) Http2Frame(com.webpieces.http2parser.api.dto.lib.Http2Frame)

Example 14 with Http2Header

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

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

the class HeaderDecoding method addToHeaders.

private Object addToHeaders(List<Http2Header> headers, Consumer<Http2Header> knownHeaders, byte[] name, byte[] value, boolean sensitive, String logId, int streamId) {
    String h = new String(name);
    String v = new String(value);
    if (!h.equals(h.toLowerCase()))
        throw new StreamException(CancelReasonCode.HEADER_NOT_LOWER_CASE, logId, streamId, "header=" + h + " was not lower case in stream=" + streamId);
    Http2Header header = new Http2Header(h, v);
    headers.add(header);
    if (knownHeaders != null) {
        Http2HeaderName knownName = Http2HeaderName.lookup(h);
        if (knownName != null)
            knownHeaders.accept(header);
    }
    return null;
}
Also used : Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2HeaderName(com.webpieces.http2parser.api.dto.lib.Http2HeaderName) StreamException(com.webpieces.http2parser.api.dto.error.StreamException)

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