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;
}
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;
}
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;
}
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;
}
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()));
}
Aggregations