use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class Http2Requests method createRequest.
public static Http2Request createRequest(int streamId, 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.setStreamId(streamId);
request.setEndOfStream(eos);
return request;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class TestS4FrameSizeAndHeaders 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.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class TestS4FrameSizeAndHeaders 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.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class DefaultCorsProcessor method processOptionsCors.
@Override
public void processOptionsCors(Http2Request request, List<HttpMethod> methods, ResponseStreamHandle responseStream) {
Http2Header originHeader = request.getHeaderLookupStruct().getHeader(Http2HeaderName.ORIGIN);
if (originHeader == null)
throw new IllegalStateException("Should only use this for CORS which requires an Origin header");
else if (!allowedDomains.contains("*") && !allowedDomains.contains(originHeader.getValue())) {
send403Response(responseStream, request);
return;
}
Http2Response response = new Http2Response();
Http2Header methodHeader = request.getHeaderLookupStruct().getHeader(Http2HeaderName.ACCESS_CONTROL_REQUEST_METHOD);
HttpMethod lookup = HttpMethod.lookup(methodHeader.getValue());
Http2Header headersRequested = request.getHeaderLookupStruct().getHeader(Http2HeaderName.ACCESS_CONTROL_REQUEST_HEADERS);
if (!methods.contains(lookup)) {
response.addHeader(new Http2Header(Http2HeaderName.STATUS, "403"));
} else if (hasInvalidHeader(allowedHeaders, headersRequested)) {
response.addHeader(new Http2Header(Http2HeaderName.STATUS, "403"));
} else {
response.addHeader(new Http2Header(Http2HeaderName.STATUS, "204"));
}
response.addHeader(new Http2Header(Http2HeaderName.ACCESS_CONTROL_ALLOW_ORIGIN, originHeader.getValue()));
if (allowedDomains.contains("*")) {
// since all domains, we must tell caches that Origin header in response will vary
// since it responds with the domain that requested it
response.addHeader(new Http2Header(Http2HeaderName.VARY, "Origin"));
}
if (isAllowCredsCookies) {
response.addHeader(new Http2Header(Http2HeaderName.ACCESS_CONTROL_ALLOW_CREDENTIALS, "true"));
}
String allowedMethodsStr = methods.stream().map(e -> e.getCode()).collect(Collectors.joining(", "));
String allowedHeadersStr = String.join(", ", allowedHeaders);
response.addHeader(new Http2Header(Http2HeaderName.ACCESS_CONTROL_ALLOW_METHODS, allowedMethodsStr));
response.addHeader(new Http2Header(Http2HeaderName.ACCESS_CONTROL_ALLOW_HEADERS, allowedHeadersStr));
if (exposeTheseResponseHeadersToBrowserStr != null) {
response.addHeader(new Http2Header(Http2HeaderName.ACCESS_CONTROL_EXPOSE_HEADERS, exposeTheseResponseHeadersToBrowserStr));
}
response.addHeader(new Http2Header(Http2HeaderName.ACCESS_CONTROL_MAX_AGE, maxAgeSeconds + ""));
response.addHeader(new Http2Header(Http2HeaderName.CONTENT_LENGTH, "0"));
sendResponse(responseStream, response);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class DefaultCorsProcessor method isAccessAllowed.
@Override
public AccessResult isAccessAllowed(RequestContext ctx) {
Http2Request request = ctx.getRequest().originalRequest;
Http2Header originHeader = request.getHeaderLookupStruct().getHeader(Http2HeaderName.ORIGIN);
if (originHeader == null) {
throw new IllegalStateException("Should only use this for CORS which requires an Origin header");
} else if (!allowedDomains.contains("*") && !allowedDomains.contains(originHeader.getValue())) {
return new AccessResult("Domain not allowed");
}
// method is allowed since we are here OR else CORSProcessor is not called
List<Http2Header> headers = request.getHeaders();
for (Http2Header header : headers) {
if (DEFAULTS.contains(header.getName())) {
continue;
} else if (!isAllowCredsCookies && header.getKnownName() == Http2HeaderName.COOKIE) {
return new AccessResult("Credentials / Cookies not supported on this CORS request");
} else if (!allowedHeaders.contains("*") && !allowedHeaders.contains(header.getName().toLowerCase())) {
return new AccessResult("Header '" + header.getName() + "' not supported on this CORS request");
}
}
ctx.addModifyResponse(new OverwriteForCorsResponse(originHeader));
return new AccessResult();
}
Aggregations