Search in sources :

Example 41 with Http2Header

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

the class Translations2 method translate.

public static FullResponse translate(HttpFullResponse r) {
    Http2Response headers = new Http2Response();
    HttpResponse http1Response = r.getResponse();
    for (Header http1Header : http1Response.getHeaders()) {
        headers.addHeader(new Http2Header(http1Header.getName(), http1Header.getValue()));
    }
    HttpResponseStatus status = http1Response.getStatusLine().getStatus();
    headers.addHeader(new Http2Header(Http2HeaderName.STATUS, "" + status.getCode()));
    DataWrapper data = r.getData();
    FullResponse http2Response = new FullResponse(headers, data, null);
    return http2Response;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Header(org.webpieces.httpparser.api.common.Header) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) HttpFullResponse(org.webpieces.httpclient11.api.HttpFullResponse) FullResponse(org.webpieces.http2client.api.dto.FullResponse) HttpResponseStatus(org.webpieces.httpparser.api.dto.HttpResponseStatus) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse)

Example 42 with Http2Header

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

the class HeaderEncoding method createHeaderFrames.

private List<Http2Frame> createHeaderFrames(HasHeaderFragment initialFrame, List<Http2Header> headers, Encoder encoder, long maxFrameSize) {
    int maxSize = (int) maxFrameSize;
    if (maxFrameSize > Integer.MAX_VALUE)
        throw new IllegalStateException("max frame size too large for this hpack library");
    List<Http2Frame> headerFrames = new LinkedList<>();
    DataWrapper serializedHeaders = serializeHeaders(encoder, headers);
    HasHeaderFragment currentFrame = initialFrame;
    HasHeaderFragment lastFrame = currentFrame;
    DataWrapper dataLeftOver = serializedHeaders;
    while (dataLeftOver.getReadableSize() > 0) {
        lastFrame = currentFrame;
        int splitSize = Math.min(dataLeftOver.getReadableSize(), maxSize);
        List<? extends DataWrapper> split = dataGen.split(dataLeftOver, splitSize);
        DataWrapper fragment = split.get(0);
        currentFrame.setHeaderFragment(fragment);
        headerFrames.add(currentFrame);
        currentFrame = new ContinuationFrame();
        currentFrame.setStreamId(initialFrame.getStreamId());
        dataLeftOver = split.get(1);
    }
    // last frame is currentFrame so set end header
    lastFrame.setEndHeaders(true);
    return headerFrames;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HasHeaderFragment(com.webpieces.http2.api.dto.lowlevel.lib.HasHeaderFragment) ContinuationFrame(com.webpieces.http2.api.dto.lowlevel.ContinuationFrame) Http2Frame(com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame) LinkedList(java.util.LinkedList)

Example 43 with Http2Header

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

the class IntegMultiThreaded method createRequest.

private static List<Http2Header> createRequest(String host, boolean isHttp, String path) {
    String scheme;
    if (isHttp)
        scheme = "http";
    else
        scheme = "https";
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.METHOD, "GET"));
    headers.add(new Http2Header(Http2HeaderName.AUTHORITY, host));
    headers.add(new Http2Header(Http2HeaderName.PATH, path));
    headers.add(new Http2Header(Http2HeaderName.SCHEME, scheme));
    headers.add(new Http2Header("host", host));
    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"));
    return headers;
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 44 with Http2Header

use of com.webpieces.http2.api.dto.lowlevel.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.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList)

Example 45 with Http2Header

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

the class Http2Requests method createResponse.

public static Http2Response createResponse(int streamId, boolean eos) {
    List<Http2Header> headers = new ArrayList<>();
    headers.add(new Http2Header(Http2HeaderName.SERVER, "id"));
    headers.add(new Http2Header(Http2HeaderName.STATUS, "200"));
    Http2Response response = new Http2Response(headers);
    response.setEndOfStream(eos);
    response.setStreamId(streamId);
    return response;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) ArrayList(java.util.ArrayList)

Aggregations

Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)72 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)26 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)23 ArrayList (java.util.ArrayList)23 DataWrapper (org.webpieces.data.api.DataWrapper)9 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)8 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)7 XFuture (org.webpieces.util.futures.XFuture)7 InetSocketAddress (java.net.InetSocketAddress)6 Header (org.webpieces.httpparser.api.common.Header)6 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)5 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)5 List (java.util.List)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ResponseStreamHandle (com.webpieces.http2.api.streaming.ResponseStreamHandle)4 Executor (java.util.concurrent.Executor)4 Executors (java.util.concurrent.Executors)4