use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.
the class TestC4FrameSizeAndHeaders 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 TestC4FrameSizeAndHeaders 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 ProxyResponse method sendChunkedResponse.
private CompletableFuture<Void> sendChunkedResponse(Http2Response resp, byte[] bytes, final Compression compression) {
boolean compressed = false;
Compression usingCompression;
if (compression == null) {
usingCompression = new NoCompression();
} else {
usingCompression = compression;
compressed = true;
resp.addHeader(new Http2Header(Http2HeaderName.CONTENT_ENCODING, usingCompression.getCompressionType()));
}
log.info("sending RENDERHTML response. size=" + bytes.length + " code=" + resp + " for domain=" + routerRequest.domain + " path" + routerRequest.relativePath + " responseSender=" + stream);
boolean isCompressed = compressed;
// Send the headers and get the responseid.
return stream.sendResponse(resp).thenCompose(writer -> {
List<DataFrame> frames = possiblyCompress(bytes, usingCompression, isCompressed);
CompletableFuture<StreamWriter> future = CompletableFuture.completedFuture(writer);
for (int i = 0; i < frames.size(); i++) {
DataFrame f = frames.get(i);
if (i == frames.size() - 1)
f.setEndOfStream(true);
future = future.thenCompose(v -> {
return writer.processPiece(f);
});
}
return future;
}).thenApply(w -> null);
}
use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.
the class ProxyResponse method createRedirect.
private Http2Response createRedirect(RedirectResponse httpResponse) {
Http2Response response = new Http2Response();
if (httpResponse.isAjaxRedirect) {
response.addHeader(new Http2Header(Http2HeaderName.STATUS, BootstrapModalTag.AJAX_REDIRECT_CODE + ""));
response.addHeader(new Http2Header("reason", "Ajax Redirect"));
} else {
response.addHeader(new Http2Header(Http2HeaderName.STATUS, StatusCode.HTTP_303_SEEOTHER.getCodeString()));
response.addHeader(new Http2Header("reason", StatusCode.HTTP_303_SEEOTHER.getReason()));
}
String url = httpResponse.redirectToPath;
if (url.startsWith("http")) {
//do nothing
} else if (httpResponse.domain != null && httpResponse.isHttps != null) {
String prefix = "http://";
if (httpResponse.isHttps)
prefix = "https://";
String portPostfix = "";
if (httpResponse.port != 443 && httpResponse.port != 80)
portPostfix = ":" + httpResponse.port;
url = prefix + httpResponse.domain + portPostfix + httpResponse.redirectToPath;
} else if (httpResponse.domain != null) {
throw new IllegalReturnValueException("Controller is returning a domain without returning isHttps=true or" + " isHttps=false so we can form the entire redirect. Either drop the domain or set isHttps");
} else if (httpResponse.isHttps != null) {
throw new IllegalReturnValueException("Controller is returning isHttps=" + httpResponse.isHttps + " but there is" + "no domain set so we can't form the full redirect. Either drop setting isHttps or set the domain");
}
Http2Header location = new Http2Header(Http2HeaderName.LOCATION, url);
response.addHeader(location);
responseCreator.addCommonHeaders(request, response, false, true);
//Firefox requires a content length of 0 on redirect(chrome doesn't)!!!...
response.addHeader(new Http2Header(Http2HeaderName.CONTENT_LENGTH, 0 + ""));
return response;
}
use of com.webpieces.http2parser.api.dto.lib.Http2Header in project webpieces by deanhiller.
the class RequestStreamWriter method handleCompleteRequest.
CompletableFuture<Void> handleCompleteRequest() {
for (Http2Header h : requestHeaders.getHeaders()) {
if (!headersSupported.contains(h.getKnownName()))
log.error("This webserver has not thought about supporting header=" + h.getName() + " quite yet. value=" + h.getValue() + " Please let us know and we can quickly add support");
}
RouterRequest routerRequest = new RouterRequest();
routerRequest.orginalRequest = requestHeaders;
//TODO(dhiller): figure out the firewall way to config when firewall terminates the ssl and we receive http
//or the secure routes will not show up
//We could add configuration to checking the terminating server socket locally as the firewall could
//be defined to terminate ssl and drive to a specific port then. the info is in stream.getSocket.getSvrSocketAddress
routerRequest.isHttps = stream.getSocket().isHttps();
String domain = requestHeaders.getAuthority();
if (domain == null) {
throw new IllegalArgumentException("Must contain Host(http1.1) or :authority(http2) header");
}
int port = 80;
if (routerRequest.isHttps)
port = 443;
//if there is a firewall this port is wrong....and the above or below is right
//int port = socketInfo.getLocalBoundAddress().getPort();
int index2 = domain.indexOf(":");
//TODO(dhiller): find when user is used and test implement
if (index2 >= 0) {
port = Integer.parseInt(domain.substring(index2 + 1));
domain = domain.substring(0, index2);
}
String methodString = requestHeaders.getMethodString();
HttpMethod method = HttpMethod.lookup(methodString);
if (method == null)
throw new UnsupportedOperationException("method not supported=" + methodString);
parseCookies(requestHeaders, routerRequest);
parseAcceptLang(requestHeaders, routerRequest);
parseAccept(requestHeaders, routerRequest);
routerRequest.encodings = headerParser.parseAcceptEncoding(requestHeaders);
String referHeader = requestHeaders.getSingleHeaderValue(Http2HeaderName.REFERER);
if (referHeader != null)
routerRequest.referrer = referHeader;
String xRequestedWithHeader = requestHeaders.getSingleHeaderValue(Http2HeaderName.X_REQUESTED_WITH);
if ("XMLHttpRequest".equals(xRequestedWithHeader))
routerRequest.isAjaxRequest = true;
String fullPath = requestHeaders.getPath();
if (fullPath == null)
throw new IllegalArgumentException(":path header(http2) or path in request line(http1.1) is required");
parseBody(requestHeaders, routerRequest);
routerRequest.method = method;
routerRequest.domain = domain;
routerRequest.port = port;
int index = fullPath.indexOf("?");
if (index > 0) {
routerRequest.relativePath = fullPath.substring(0, index);
String postfix = fullPath.substring(index + 1);
facade.urlEncodeParse(postfix, routerRequest);
} else {
routerRequest.queryParams = new HashMap<>();
routerRequest.relativePath = fullPath;
}
//http1.1 so no...
routerRequest.isSendAheadNextResponses = false;
if (routerRequest.relativePath.contains("?"))
throw new UnsupportedOperationException("not supported yet");
ProxyResponse streamer = facade.createProxyResponse();
try {
streamer.init(routerRequest, requestHeaders, stream, facade.getBufferPool());
return facade.incomingCompleteRequest(routerRequest, streamer);
} catch (BadCookieException e) {
log.warn("This occurs if secret key changed, or you booted another webapp with different key on same port or someone modified the cookie", e);
streamer.sendRedirectAndClearCookie(routerRequest, e.getCookieName());
return CompletableFuture.completedFuture(null);
}
}
Aggregations