use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class TestC5_1StreamStates method testSection5_1BadFrameReceivedInIdleState.
/**
* Receiving any frame other than HEADERS or PRIORITY on a stream in this state
* MUST be treated as a connection error (Section 5.4.1) of type PROTOCOL_ERROR.
*/
@Test
public void testSection5_1BadFrameReceivedInIdleState() {
DataFrame dataFrame = new DataFrame(1, false);
//endOfStream=false
mockChannel.write(dataFrame);
//remote receives goAway
GoAwayFrame goAway = (GoAwayFrame) mockChannel.getFrameAndClear();
Assert.assertEquals(Http2ErrorCode.PROTOCOL_ERROR, goAway.getKnownErrorCode());
DataWrapper debugData = goAway.getDebugData();
String msg = debugData.createStringFromUtf8(0, debugData.getReadableSize());
Assert.assertEquals("ConnectionException: MockHttp2Channel1:stream1:(BAD_FRAME_RECEIVED_FOR_THIS_STATE) " + "Stream in idle state and received this frame which should not happen in " + "idle state. frame=DataFrame{streamId=1, endStream=false, data.len=0, padding=0}", msg);
Assert.assertTrue(mockChannel.isClosed());
//send new request on closed connection
MockResponseListener listener1 = new MockResponseListener();
Http2Request request1 = Requests.createRequest();
CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
ConnectionClosedException intercept = (ConnectionClosedException) TestAssert.intercept(future);
Assert.assertTrue(intercept.getMessage().contains("Connection closed or closing"));
Assert.assertEquals(0, mockChannel.getFramesAndClear().size());
}
use of com.webpieces.hpack.api.dto.Http2Request 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());
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class TestCBasicRequestResponse method testPushPromise.
@Test
public void testPushPromise() {
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(CompletableFuture.<StreamWriter>completedFuture(null));
Http2Request request = sendRequestToServer(listener1);
sendPushPromise(listener1, request.getStreamId(), true);
sendResponseFromServer(listener1, request);
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class AbstractTest method sendRequestToServer.
protected Http2Request sendRequestToServer(MockResponseListener listener1) {
Http2Request request1 = Requests.createRequest();
httpSocket.openStream().process(request1, listener1);
Http2Msg req = mockChannel.getFrameAndClear();
Assert.assertEquals(request1, req);
return request1;
}
use of com.webpieces.hpack.api.dto.Http2Request in project webpieces by deanhiller.
the class TestCMaxConcurrentSetting method sendTwoRequests.
private RequestsSent sendTwoRequests() {
Http2Request request1 = Requests.createRequest();
Http2Request request2 = Requests.createRequest();
MockStreamWriter writer1 = new MockStreamWriter();
MockStreamWriter writer2 = new MockStreamWriter();
MockResponseListener listener1 = new MockResponseListener();
listener1.setIncomingRespDefault(CompletableFuture.completedFuture(writer1));
//do not set default incoming response as we want to delay the resolution of the future
MockResponseListener listener2 = new MockResponseListener();
CompletableFuture<StreamWriter> future = httpSocket.openStream().process(request1, listener1);
CompletableFuture<StreamWriter> future2 = httpSocket.openStream().process(request2, listener2);
RequestHolder r1 = new RequestHolder(request1, listener1, writer1, future);
RequestHolder r2 = new RequestHolder(request2, listener2, writer2, future2);
RequestsSent requests = new RequestsSent(r1, r2);
Http2Msg req = mockChannel.getFrameAndClear();
Assert.assertEquals(1, req.getStreamId());
Assert.assertEquals(request1, req);
Assert.assertTrue(future.isDone());
Assert.assertFalse(future2.isDone());
return requests;
}
Aggregations