use of com.webpieces.http2.api.dto.highlevel.Http2Trailers in project webpieces by deanhiller.
the class ResponseCacher method run.
public XFuture<FullResponse> run(FullRequest request) {
SingleResponseListener responseListener = new SingleResponseListener();
RequestStreamHandle streamHandle = openStreamFunc.get();
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);
StreamRef streamRef = streamHandle.process(request.getHeaders(), responseListener);
return streamRef.getWriter().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);
StreamRef streamRef = streamHandle.process(request.getHeaders(), responseListener);
return streamRef.getWriter().thenCompose(writer -> writeStuff(writer, req, data, trailers, responseListener));
}
use of com.webpieces.http2.api.dto.highlevel.Http2Trailers in project webpieces by deanhiller.
the class TestSBasicRequestResponse method testWithDataAndTrailingHeaders.
@Test
public void testWithDataAndTrailingHeaders() throws InterruptedException, ExecutionException, TimeoutException {
MockStreamWriter mockSw = new MockStreamWriter();
mockSw.setDefaultRetValToThis();
mockListener.addMockStreamToReturn(mockSw);
Http2Request request1 = Http2Requests.createRequest(1, false);
DataFrame data1 = Http2Requests.createData1(request1.getStreamId(), false);
Http2Trailers trailing = Http2Requests.createTrailers(request1.getStreamId());
mockChannel.send(request1);
PassedIn incoming1 = mockListener.getSingleRequest();
Assert.assertEquals(request1, incoming1.request);
mockChannel.send(data1);
DataFrame incoming2 = (DataFrame) mockSw.getSingleFrame();
Assert.assertEquals(3, incoming2.getData().getReadableSize());
// clear window update frames
Assert.assertEquals(2, mockChannel.getFramesAndClear().size());
mockChannel.send(trailing);
Http2Headers incoming = (Http2Headers) mockSw.getSingleFrame();
Assert.assertEquals(trailing, incoming);
Http2Response resp = Http2Requests.createResponse(request1.getStreamId(), false);
XFuture<StreamWriter> future = incoming1.stream.process(resp);
Http2Msg response = mockChannel.getFrameAndClear();
Assert.assertEquals(resp, response);
StreamWriter writer = future.get(2, TimeUnit.SECONDS);
DataFrame data2 = Http2Requests.createData2(request1.getStreamId(), false);
writer.processPiece(data2);
DataFrame dataResp = (DataFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(1, dataResp.getData().getReadableSize());
Http2Trailers trailingResp = Http2Requests.createTrailers(request1.getStreamId());
writer.processPiece(trailingResp);
Http2Headers trailers = (Http2Headers) mockChannel.getFrameAndClear();
Assert.assertEquals(trailingResp, trailers);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Trailers in project webpieces by deanhiller.
the class Requests method createTrailers.
public static Http2Trailers createTrailers() {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.ACCEPT, "*/*"));
headers.add(new Http2Header(Http2HeaderName.ACCEPT_ENCODING, "gzip, deflate"));
headers.add(new Http2Header(Http2HeaderName.USER_AGENT, "webpieces/1.15.0"));
Http2Trailers trailers = new Http2Trailers(headers);
return trailers;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Trailers in project webpieces by deanhiller.
the class Http2Requests method createTrailers.
public static Http2Trailers createTrailers(int streamId) {
List<Http2Header> headers = new ArrayList<>();
headers.add(new Http2Header(Http2HeaderName.SERVER, "trailing"));
Http2Trailers trailers = new Http2Trailers(headers);
trailers.setEndOfStream(true);
trailers.setStreamId(streamId);
return trailers;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Trailers in project webpieces by deanhiller.
the class Level8NotifyClntListeners method sendPieceToApp.
@Override
public XFuture<Void> sendPieceToApp(Stream stream, Http2Trailers payload) {
ClientStream str = (ClientStream) stream;
StreamWriter writer = str.getResponseWriter();
return writer.processPiece(payload).thenApply(null);
}
Aggregations