Search in sources :

Example 1 with OverwritePlatformResponse

use of org.webpieces.ctx.api.OverwritePlatformResponse in project webpieces by deanhiller.

the class CompressionChunkingHandle method process.

@Override
public XFuture<StreamWriter> process(Http2Response response) {
    if (lastResponseSent != null)
        throw new IllegalStateException("You already sent a response.  " + "do not call Actions.redirect or Actions.render more than once.  previous response=" + lastResponseSent + " 2nd response=" + response);
    lastResponseSent = response;
    Compression compression = checkForCompression(response);
    ChunkedStream chunkedStream = new ChunkedStream(webSettings.getMaxBodySizeToSend());
    Http2Response finalResp = response;
    if (Current.isContextSet()) {
        // in some exceptional cases like incoming cookies failing to parse, there will be no context
        List<OverwritePlatformResponse> callbacks = Current.getContext().getCallbacks();
        for (OverwritePlatformResponse callback : callbacks) {
            finalResp = (Http2Response) callback.modifyOrReplace(finalResp);
        }
    }
    boolean closeAfterResponding = false;
    if (closeAfterResponding(originalRequest))
        closeAfterResponding = true;
    boolean shouldClose = closeAfterResponding;
    return handler.process(response).thenApply(w -> possiblyClose(shouldClose, response, w)).thenApply(w -> new ProxyStreamWriter(shouldClose, compression, chunkedStream, w));
}
Also used : SneakyThrow(org.webpieces.util.exceptions.SneakyThrow) Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) Inject(javax.inject.Inject) RouterRequest(org.webpieces.ctx.api.RouterRequest) StreamMsg(com.webpieces.http2.api.dto.lowlevel.lib.StreamMsg) Map(java.util.Map) DataWrapper(org.webpieces.data.api.DataWrapper) CompressionLookup(org.webpieces.router.impl.compression.CompressionLookup) OutputStream(java.io.OutputStream) WebSettings(org.webpieces.router.impl.routeinvoker.WebSettings) CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) IOException(java.io.IOException) List(java.util.List) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) XFuture(org.webpieces.util.futures.XFuture) OverwritePlatformResponse(org.webpieces.ctx.api.OverwritePlatformResponse) MimeTypes(org.webpieces.router.impl.compression.MimeTypes) RouterResponseHandler(org.webpieces.router.api.RouterResponseHandler) Http2MsgType(com.webpieces.http2.api.dto.lowlevel.lib.Http2MsgType) Http2Header(com.webpieces.http2.api.dto.lowlevel.lib.Http2Header) StreamWriter(com.webpieces.http2.api.streaming.StreamWriter) Http2HeaderName(com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName) PushStreamHandle(com.webpieces.http2.api.streaming.PushStreamHandle) Current(org.webpieces.ctx.api.Current) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Compression(org.webpieces.router.impl.compression.Compression) Http2Response(com.webpieces.http2.api.dto.highlevel.Http2Response) Compression(org.webpieces.router.impl.compression.Compression) OverwritePlatformResponse(org.webpieces.ctx.api.OverwritePlatformResponse)

Aggregations

Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)1 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)1 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)1 CancelReason (com.webpieces.http2.api.dto.lowlevel.CancelReason)1 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)1 Http2Header (com.webpieces.http2.api.dto.lowlevel.lib.Http2Header)1 Http2HeaderName (com.webpieces.http2.api.dto.lowlevel.lib.Http2HeaderName)1 Http2MsgType (com.webpieces.http2.api.dto.lowlevel.lib.Http2MsgType)1 StreamMsg (com.webpieces.http2.api.dto.lowlevel.lib.StreamMsg)1 PushStreamHandle (com.webpieces.http2.api.streaming.PushStreamHandle)1 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 List (java.util.List)1 Map (java.util.Map)1 Inject (javax.inject.Inject)1 Current (org.webpieces.ctx.api.Current)1 OverwritePlatformResponse (org.webpieces.ctx.api.OverwritePlatformResponse)1 RouterRequest (org.webpieces.ctx.api.RouterRequest)1 DataWrapper (org.webpieces.data.api.DataWrapper)1