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