use of org.webpieces.frontend2.api.HttpStream in project webpieces by deanhiller.
the class Layer2Http1_1Handler method processInitialPieceOfRequest.
private CompletableFuture<Void> processInitialPieceOfRequest(FrontendSocketImpl socket, HttpRequest http1Req, Http2Request headers) {
int id = counter.getAndAdd(2);
PermitQueue permitQueue = socket.getPermitQueue();
return permitQueue.runRequest(() -> {
Http1_1StreamImpl currentStream = new Http1_1StreamImpl(id, socket, httpParser, permitQueue);
HttpStream streamHandle = httpListener.openStream();
currentStream.setStreamHandle(streamHandle);
socket.setCurrentStream(currentStream);
if (!headers.isEndOfStream()) {
//data run right after the request
return streamHandle.incomingRequest(headers, currentStream).thenApply(w -> {
currentStream.setRequestWriter(w);
permitQueue.releasePermit();
return null;
});
} else {
//in this case, since this is the END of the request, we cannot release the permit in the
//permit queue as we do not want to let the next request to start until the full response is
//sent back to the client
currentStream.setSentFullRequest(true);
return streamHandle.incomingRequest(headers, currentStream).thenApply(w -> {
currentStream.setRequestWriter(w);
return null;
});
}
});
}
Aggregations