use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class ResponseWrapperHttp2 method uncompressBodyAndAssertContainsString.
public void uncompressBodyAndAssertContainsString(String text) {
Http2Header header = getResponse().getHeaderLookupStruct().getHeader(Http2HeaderName.CONTENT_ENCODING);
if (header == null)
throw new IllegalStateException("Body is not compressed as no CONTENT_ENCODING header field exists");
else if (!"gzip".equals(header.getValue()))
throw new IllegalStateException("Body has wrong compression type=" + header.getValue() + " in CONTENT_ENCODING header field");
DataWrapper wrapper = getBody();
byte[] compressed = wrapper.createByteArray();
ByteArrayInputStream in = new ByteArrayInputStream(compressed);
byte[] out = new byte[10000];
DataWrapper output = dataGen.emptyWrapper();
try (GZIPInputStream str = new GZIPInputStream(in)) {
int read = 0;
while ((read = str.read(out)) > 0) {
ByteBuffer buffer = ByteBuffer.wrap(out, 0, read);
DataWrapper byteWrapper = dataGen.wrapByteBuffer(buffer);
output = dataGen.chainDataWrappers(output, byteWrapper);
out = new byte[10000];
}
} catch (IOException e) {
throw SneakyThrow.sneak(e);
}
Charset charset = extractCharset();
String bodyAsString = output.createStringFrom(0, output.getReadableSize(), charset);
if (!bodyAsString.contains(text))
throw new IllegalStateException("Expected compressed body to contain='" + text + "' but body was=" + bodyAsString);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class ResponseWrapperHttp2 method assertContentType.
public void assertContentType(String mimeType) {
Http2Header type = getResponse().getHeaderLookupStruct().getHeader(Http2HeaderName.CONTENT_TYPE);
String value = type.getValue();
if (!mimeType.equals(value))
throw new IllegalStateException("Expected mimeType=" + mimeType + " but found type=" + value);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class RequestCreation method createHttpRequest.
public static Http2Request createHttpRequest(HttpMethod method, String path) {
Http2Request req = new Http2Request();
req.addHeader(new Http2Header(Http2HeaderName.METHOD, method.getCode()));
req.addHeader(new Http2Header(Http2HeaderName.PATH, path));
req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "http"));
req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "orderly.com"));
return req;
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class DefaultCorsProcessor method send403Response.
private void send403Response(ResponseStreamHandle responseStream, Http2Request request) {
Http2Response response = new Http2Response();
response.addHeader(new Http2Header(Http2HeaderName.STATUS, "403"));
response.addHeader(new Http2Header(Http2HeaderName.VARY, "Origin"));
sendResponse(responseStream, response);
}
use of com.webpieces.http2.api.dto.lowlevel.lib.Http2Header in project webpieces by deanhiller.
the class InstallSslCertController method modifyResponse.
private Object modifyResponse(Object http2Response) {
Http2Response resp = (Http2Response) http2Response;
Http2Header header = resp.getHeaderLookupStruct().getHeader(Http2HeaderName.CONTENT_TYPE);
header.setValue("text/plain");
return resp;
}
Aggregations