use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class IntegMultiThreaded method main.
public static void main(String[] args) throws InterruptedException {
boolean isHttp = true;
String path = "/";
// String host = www.google.com;
// String host = "localhost"; //jetty
String host = "nghttp2.org";
int port = 443;
if (isHttp)
port = 80;
if (host.equals("localhost")) {
// IF jetty, use a path with a bigger download
path = "/test/data.txt";
port = 8443;
if (isHttp)
port = 8080;
}
List<Http2Header> req = createRequest(host, isHttp, path);
log.info("starting socket");
InetSocketAddress addr = new InetSocketAddress(host, port);
Http2Socket socket = IntegSingleRequest.createHttpClient("clientSocket", isHttp, addr);
socket.connect(addr).thenApply(s -> {
for (int i = 0; i < 99; i += 100) {
executor.execute(new WorkItem(socket, req, i, i));
}
return s;
}).exceptionally(e -> {
reportException(socket, e);
return null;
});
Thread.sleep(100000000);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Requests method createResponse.
public static Http2Response createResponse(int streamId) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.STATUS, String.valueOf(StatusCode.HTTP_200_OK.getCode())));
headers.add(new Http2Header(Http2HeaderName.SERVER, "me"));
Http2Response response = new Http2Response(headers);
response.setEndOfStream(false);
response.setStreamId(streamId);
return response;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Requests method createRequest.
static Http2Request createRequest(boolean eos) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.METHOD, "GET"));
headers.add(new Http2Header(Http2HeaderName.AUTHORITY, "somehost.com"));
headers.add(new Http2Header(Http2HeaderName.PATH, "/"));
headers.add(new Http2Header(Http2HeaderName.SCHEME, "http"));
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"));
Http2Request request = new Http2Request(headers);
request.setEndOfStream(eos);
return request;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class IntegColoradoEdu method createRequest.
private static Http2Request createRequest(String host) {
// GET / HTTP/1.1
// Host: www.colorado.edu
// User-Agent: curl/7.43.0
// Accept: */*
//
// HttpRequestLine requestLine = new HttpRequestLine();
// requestLine.setMethod(KnownHttpMethod.GET);
// requestLine.setUri(new HttpUri("/"));
//
// HttpRequest req = new HttpRequest();
// req.setRequestLine(requestLine);
// req.addHeader(new Header(KnownHeaderName.HOST, host));
// req.addHeader(new Header(KnownHeaderName.ACCEPT, "*/*"));
// req.addHeader(new Header(KnownHeaderName.USER_AGENT, "webpieces/0.9"));
Http2Request req = new Http2Request();
req.addHeader(new Http2Header(Http2HeaderName.METHOD, "GET"));
req.addHeader(new Http2Header(Http2HeaderName.PATH, "GET"));
req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "http"));
req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "www.colorado.edu"));
req.addHeader(new Http2Header(Http2HeaderName.USER_AGENT, "webpieces/0.9"));
req.addHeader(new Http2Header(Http2HeaderName.ACCEPT, "*/*"));
return req;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class HeaderDecoding method decodeImpl.
private List<Http2Header> decodeImpl(UnmarshalStateImpl state, DataWrapper data, int streamId, Consumer<Http2Header> knownHeaders) throws IOException {
List<Http2Header> headers = new ArrayList<>();
byte[] bytes = data.createByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
Decoder decoder = state.getDecoder();
// TODO(dhiller): make this an async syncrhonized block instead so threads can keep running!!!
synchronized (decoder) {
decoder.decode(in, (n, v, s) -> addToHeaders(headers, knownHeaders, n, v, s, state.getLogId(), streamId));
decoder.endHeaderBlock();
}
if (data.getReadableSize() > 0 && headers.size() == 0)
throw new ConnectionException(CancelReasonCode.COMPRESSION_ERROR, state.getLogId(), streamId, "Header data came in, but no headers came out");
return headers;
}
Aggregations