use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Translations2 method translate.
public static HttpFullRequest translate(FullRequest request) {
// String scheme = request.getHeaders().getScheme();
Http2Request headers = request.getHeaders();
String authority = headers.getAuthority();
String path = headers.getPath();
String methodString = headers.getMethodString();
if (methodString == null)
throw new IllegalArgumentException("http2 :method header is required");
else if (authority == null) {
throw new IllegalArgumentException("http1 required host header so http2 message must have :authority header set");
}
HttpRequestLine reqLine = new HttpRequestLine();
reqLine.setUri(new HttpUri(path));
reqLine.setMethod(new HttpRequestMethod(methodString));
reqLine.setVersion(new HttpVersion());
HttpRequest httpReq = new HttpRequest();
httpReq.setRequestLine(reqLine);
DataWrapper data = request.getPayload();
// translate all other headers here as well...
for (Http2Header header : headers.getHeaders()) {
if (// All standard headers go elsewhere except HOST which we do below
!header.getName().startsWith(":"))
httpReq.addHeader(new Header(header.getName(), header.getValue()));
}
httpReq.addHeader(new Header(KnownHeaderName.HOST, authority));
HttpFullRequest req = new HttpFullRequest(httpReq, data);
return req;
}
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 ResponseWrapperHttp2 method modifyCookieMap.
public Map<String, String> modifyCookieMap(Map<String, String> currentCookies) {
List<Http2Header> headers = getResponse().getHeaderLookupStruct().getHeaders(Http2HeaderName.SET_COOKIE);
for (Http2Header header : headers) {
String value = header.getValue();
if (value.contains(";")) {
String[] split = value.split(";");
value = split[0];
}
int indexOf = value.indexOf("=");
String key = value.substring(0, indexOf);
String val = value.substring(indexOf + 1);
if (val.length() <= 0) {
currentCookies.remove(key);
} else {
currentCookies.put(key, val);
}
}
return currentCookies;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class ResponseWrapperHttp2 method extractCharset.
private Charset extractCharset() {
Http2Header header = getResponse().getHeaderLookupStruct().getHeader(Http2HeaderName.CONTENT_TYPE);
if (header == null)
throw new IllegalArgumentException("no ContentType header could be found");
ContentType ct = ContentType.parse(header);
Charset charset = DEFAULT_CHARSET;
if (ct.getCharSet() != null)
charset = Charset.forName(ct.getCharSet());
return charset;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class XFileReaderFileSystem method createFileReader.
protected ChunkFileSystemReader createFileReader(Http2Response response, RenderStaticResponse renderStatic, String fileName, VirtualFile fullFilePath, RequestInfo info, String extension, ResponseEncodingTuple tuple, ProxyStreamHandle handle) {
Path file;
Compression compr = compressionLookup.createCompressionStream(info.getRouterRequest().encodings, tuple.mimeType);
// during startup as I don't feel like paying a cpu penalty for compressing while live
if (compr != null && compr.getCompressionType().equals(routerConfig.getStartupCompression())) {
handle.turnCompressionOff();
response.addHeader(new Http2Header(Http2HeaderName.CONTENT_ENCODING, compr.getCompressionType()));
File routesCache = renderStatic.getTargetCache();
String relativeUrl = renderStatic.getRelativeUrl();
File fileReference;
if (relativeUrl == null) {
fileReference = FileFactory.newFile(routesCache, fileName);
} else {
fileReference = FileFactory.newFile(routesCache, relativeUrl);
}
file = fetchFile("Compressed File from cache=", fileReference.getAbsolutePath() + ".gz");
} else {
file = fetchFile("File=", fullFilePath.getAbsolutePath());
}
AsynchronousFileChannel asyncFile;
try {
asyncFile = AsynchronousFileChannel.open(file, options, fileExecutor);
ChunkFileSystemReader reader = new ChunkFileSystemReader(asyncFile, file);
return reader;
} catch (IOException e) {
throw new NioException("Open Channel Exception " + file, e);
}
}
Aggregations