use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.
the class Http2Translations method responseToHeaders.
public static Http2Response responseToHeaders(HttpResponse response) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.STATUS, response.getStatusLine().getStatus().getCode().toString()));
for (Header header : response.getHeaders()) {
if (header.getKnownName() == KnownHeaderName.TRANSFER_ENCODING) {
if ("chunked".equals(header.getValue())) {
//skip as http2 does not allow this header
continue;
}
}
headers.add(new Http2Header(header.getName(), header.getValue()));
}
Http2Response resp = new Http2Response(headers);
Header header = response.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
if (header != null) {
int len = Integer.parseInt(header.getValue());
if (len == 0) {
resp.setEndOfStream(true);
} else {
resp.setEndOfStream(false);
}
} else {
resp.setEndOfStream(false);
}
return resp;
}
use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.
the class Http2Requests method createResponse.
public static Http2Response createResponse(int streamId, boolean eos) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.SERVER, "id"));
headers.add(new Http2Header(Http2HeaderName.STATUS, "200"));
Http2Response response = new Http2Response(headers);
response.setEndOfStream(eos);
response.setStreamId(streamId);
return response;
}
use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.
the class Http2Requests method createTrailers.
public static Http2Trailers createTrailers(int streamId) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.SERVER, "trailing"));
Http2Trailers trailers = new Http2Trailers(headers);
trailers.setEndOfStream(true);
trailers.setStreamId(streamId);
return trailers;
}
use of com.webpieces.http2parser.api.dto.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.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.
the class IntegMultiThreaded method createRequest.
private static List<Http2Header> createRequest(String host, boolean isHttp, String path) {
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, path));
headers.add(new Http2Header(Http2HeaderName.SCHEME, scheme));
headers.add(new Http2Header("host", host));
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;
}
Aggregations