Search in sources :

Example 36 with Http2Header

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

Example 37 with Http2Header

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

Example 38 with Http2Header

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

the class Requests method createRequest.

public static Http2Request createRequest(String uri, DataWrapper body) {
    Http2Request req = new Http2Request();
    req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "yourdomain.com"));
    req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "https"));
    req.addHeader(new Http2Header(Http2HeaderName.METHOD, "GET"));
    req.addHeader(new Http2Header(Http2HeaderName.PATH, uri));
    req.addHeader(new Http2Header(Http2HeaderName.CONTENT_LENGTH, body.getReadableSize() + ""));
    return req;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 39 with Http2Header

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

the class Http2ToHttp11 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.http2.api.dto.lowlevel.lib.Http2Header) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) Http2HeaderStruct(com.webpieces.http2.api.dto.highlevel.Http2HeaderStruct)

Example 40 with Http2Header

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

the class Http2ToHttp11 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.http2.api.dto.lowlevel.lib.Http2Header)

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