Search in sources :

Example 66 with Http2Header

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);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) Charset(java.nio.charset.Charset) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 67 with Http2Header

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);
}
Also used : Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 68 with Http2Header

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;
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 69 with Http2Header

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);
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Example 70 with Http2Header

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;
}
Also used : Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)

Aggregations

Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)72 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)26 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)23 ArrayList (java.util.ArrayList)23 DataWrapper (org.webpieces.data.api.DataWrapper)9 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)8 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)7 XFuture (org.webpieces.util.futures.XFuture)7 InetSocketAddress (java.net.InetSocketAddress)6 Header (org.webpieces.httpparser.api.common.Header)6 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)5 Http2Frame (com.webpieces.http2.api.dto.lowlevel.lib.Http2Frame)5 StreamRef (com.webpieces.http2.api.streaming.StreamRef)5 List (java.util.List)5 Logger (org.slf4j.Logger)5 LoggerFactory (org.slf4j.LoggerFactory)5 ResponseStreamHandle (com.webpieces.http2.api.streaming.ResponseStreamHandle)4 Executor (java.util.concurrent.Executor)4 Executors (java.util.concurrent.Executors)4