Search in sources :

Example 1 with Http2Trailers

use of com.webpieces.hpack.api.dto.Http2Trailers in project webpieces by deanhiller.

the class Http2SocketImpl method send.

/**
	 * Can't specifically backpressure with this method(ie. On the other method, if you do not ack, eventually
	 * with too many bytes, the channelmanager disregisters and stops reading from the socket placing backpressure
	 * on the socket)
	 */
@Override
public CompletableFuture<FullResponse> send(FullRequest request) {
    SingleResponseListener responseListener = new SingleResponseListener();
    StreamHandle streamHandle = openStream();
    Http2Request req = request.getHeaders();
    if (request.getPayload() == null) {
        request.getHeaders().setEndOfStream(true);
        streamHandle.process(req, responseListener);
        return responseListener.fetchResponseFuture();
    } else if (request.getTrailingHeaders() == null) {
        request.getHeaders().setEndOfStream(false);
        DataFrame data = createData(request, true);
        return streamHandle.process(request.getHeaders(), responseListener).thenCompose(writer -> {
            data.setStreamId(req.getStreamId());
            return writer.processPiece(data);
        }).thenCompose(writer -> responseListener.fetchResponseFuture());
    }
    request.getHeaders().setEndOfStream(false);
    DataFrame data = createData(request, false);
    Http2Trailers trailers = request.getTrailingHeaders();
    trailers.setEndOfStream(true);
    return streamHandle.process(request.getHeaders(), responseListener).thenCompose(writer -> {
        data.setStreamId(req.getStreamId());
        return writer.processPiece(data);
    }).thenCompose(writer -> {
        trailers.setStreamId(req.getStreamId());
        return writer.processPiece(trailers);
    }).thenCompose(writer -> responseListener.fetchResponseFuture());
}
Also used : Logger(org.webpieces.util.logging.Logger) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) CompletableFuture(java.util.concurrent.CompletableFuture) InetSocketAddress(java.net.InetSocketAddress) FullRequest(org.webpieces.http2client.api.dto.FullRequest) Http2Request(com.webpieces.hpack.api.dto.Http2Request) Http2ClientEngineFactory(com.webpieces.http2engine.api.client.Http2ClientEngineFactory) DataWrapper(org.webpieces.data.api.DataWrapper) FullResponse(org.webpieces.http2client.api.dto.FullResponse) LoggerFactory(org.webpieces.util.logging.LoggerFactory) StreamHandle(com.webpieces.http2engine.api.StreamHandle) Http2ClientEngine(com.webpieces.http2engine.api.client.Http2ClientEngine) Http2Socket(org.webpieces.http2client.api.Http2Socket) TCPChannel(org.webpieces.nio.api.channels.TCPChannel) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) Http2Request(com.webpieces.hpack.api.dto.Http2Request) StreamHandle(com.webpieces.http2engine.api.StreamHandle) Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) DataFrame(com.webpieces.http2parser.api.dto.DataFrame)

Aggregations

Http2Request (com.webpieces.hpack.api.dto.Http2Request)1 Http2Trailers (com.webpieces.hpack.api.dto.Http2Trailers)1 StreamHandle (com.webpieces.http2engine.api.StreamHandle)1 Http2ClientEngine (com.webpieces.http2engine.api.client.Http2ClientEngine)1 Http2ClientEngineFactory (com.webpieces.http2engine.api.client.Http2ClientEngineFactory)1 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)1 InetSocketAddress (java.net.InetSocketAddress)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 Http2Socket (org.webpieces.http2client.api.Http2Socket)1 FullRequest (org.webpieces.http2client.api.dto.FullRequest)1 FullResponse (org.webpieces.http2client.api.dto.FullResponse)1 TCPChannel (org.webpieces.nio.api.channels.TCPChannel)1 Logger (org.webpieces.util.logging.Logger)1 LoggerFactory (org.webpieces.util.logging.LoggerFactory)1