use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class IntegSingleRequest method createRequest.
private static List<Http2Header> createRequest(String host, boolean isHttp) {
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, "/"));
headers.add(new Http2Header(Http2HeaderName.SCHEME, scheme));
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;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class IntegSingleRequest method start.
public void start() throws InterruptedException {
log.info("starting test to download / page from google");
boolean isHttp = true;
String host = "www.google.com";
// String host = "localhost"; //jetty
// String host = "api.push.apple.com";
// String host = "gcm-http.googleapis.com";
// String host = "nghttp2.org";
int port = 443;
if (isHttp)
port = 80;
if ("localhost".equals(host)) {
port = 8443;
if (isHttp)
port = 8080;
}
List<Http2Header> req = createRequest(host, isHttp);
Http2Request request = new Http2Request(req);
request.setEndOfStream(true);
InetSocketAddress addr = new InetSocketAddress(host, port);
Http2Socket socket = createHttpClient("testRunSocket", isHttp, addr);
socket.connect(addr).thenAccept(v -> socket.openStream().process(request, new ChunkedResponseListener())).exceptionally(e -> reportException(socket, e));
Thread.sleep(10000000);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class HpackParserImpl method combineAndSendHeadersToClient.
private void combineAndSendHeadersToClient(UnmarshalStateImpl state) {
List<HasHeaderFragment> hasHeaderFragmentList = state.getHeadersToCombine();
// Now we set the full header list on the first frame and just return that
HasHeaderFragment firstFrame = hasHeaderFragmentList.get(0);
DataWrapper allSerializedHeaders = dataGen.emptyWrapper();
for (HasHeaderFragment iterFrame : hasHeaderFragmentList) {
allSerializedHeaders = dataGen.chainDataWrappers(allSerializedHeaders, iterFrame.getHeaderFragment());
}
Map<Http2HeaderName, Http2Header> knownHeaders = new HashMap<>();
List<Http2Header> headers = decoding.decode(state, allSerializedHeaders, firstFrame.getStreamId(), header -> knownHeaders.put(header.getKnownName(), header));
if (firstFrame instanceof HeadersFrame) {
HeadersFrame f = (HeadersFrame) firstFrame;
Http2Headers fullHeaders = createCorrectType(knownHeaders, headers, state.getLogId(), f.getStreamId(), f.isEndOfStream());
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPriorityDetails(f.getPriorityDetails());
fullHeaders.setEndOfStream(f.isEndOfStream());
state.addParsedMessage(fullHeaders);
} else if (firstFrame instanceof PushPromiseFrame) {
PushPromiseFrame f = (PushPromiseFrame) firstFrame;
Http2Push fullHeaders = new Http2Push(headers);
fullHeaders.setStreamId(f.getStreamId());
fullHeaders.setPromisedStreamId(f.getPromisedStreamId());
state.addParsedMessage(fullHeaders);
}
hasHeaderFragmentList.clear();
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class TestSplitHeaders method testBytesParsedBySplittingHeaders.
@Test
public void testBytesParsedBySplittingHeaders() {
Http2Request req = new Http2Request();
req.setStreamId(1);
req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "/"));
req.addHeader(new Http2Header(Http2HeaderName.METHOD, "/"));
req.addHeader(new Http2Header(Http2HeaderName.PATH, "/"));
req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "/"));
for (int i = 0; i < 20; i++) {
req.addHeader(new Http2Header("someHeader" + i, "value"));
}
DataWrapper data = parser.marshal(req);
byte[] first = data.readBytesAt(0, 60);
DataWrapper data1 = dataGen.wrapByteArray(first);
UnmarshalState state = parser.unmarshal(data1);
Assert.assertEquals(0, state.getParsedFrames().size());
Assert.assertEquals(0, state.getNumBytesJustParsed());
Assert.assertEquals(first.length, state.getLeftOverDataSize());
byte[] second = data.readBytesAt(60, data.getReadableSize() - 60);
DataWrapper data2 = dataGen.wrapByteArray(second);
state = parser.unmarshal(data2);
Assert.assertEquals(1, state.getParsedFrames().size());
Assert.assertEquals(data.getReadableSize(), state.getNumBytesJustParsed());
Assert.assertEquals(0, state.getLeftOverDataSize());
}
use of com.webpieces.http2.api.dto.lowlevel.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 ConnectionException(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