use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class TestSplitHeaders method testBytesParsedBySplittingHeaders.
@Test
public void testBytesParsedBySplittingHeaders() {
Http2Request req = new Http2Request();
req.setStreamId(1);
req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "/"));
req.addHeader(new Http2Header(Http2HeaderName.METHOD, "/"));
req.addHeader(new Http2Header(Http2HeaderName.PATH, "/"));
req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "/"));
for (int i = 0; i < 20; i++) {
req.addHeader(new Http2Header("someHeader" + i, "value"));
}
DataWrapper data = parser.marshal(req);
byte[] first = data.readBytesAt(0, 60);
DataWrapper data1 = dataGen.wrapByteArray(first);
UnmarshalState state = parser.unmarshal(data1);
Assert.assertEquals(0, state.getParsedFrames().size());
Assert.assertEquals(0, state.getNumBytesJustParsed());
Assert.assertEquals(first.length, state.getLeftOverDataSize());
byte[] second = data.readBytesAt(60, data.getReadableSize() - 60);
DataWrapper data2 = dataGen.wrapByteArray(second);
state = parser.unmarshal(data2);
Assert.assertEquals(1, state.getParsedFrames().size());
Assert.assertEquals(data.getReadableSize(), state.getNumBytesJustParsed());
Assert.assertEquals(0, state.getLeftOverDataSize());
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class Requests method createRequest.
public static Http2Request createRequest(String uri, DataWrapper body) {
Http2Request req = new Http2Request();
req.addHeader(new Http2Header(Http2HeaderName.AUTHORITY, "yourdomain.com"));
req.addHeader(new Http2Header(Http2HeaderName.SCHEME, "https"));
req.addHeader(new Http2Header(Http2HeaderName.METHOD, "GET"));
req.addHeader(new Http2Header(Http2HeaderName.PATH, uri));
req.addHeader(new Http2Header(Http2HeaderName.CONTENT_LENGTH, body.getReadableSize() + ""));
return req;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class TestHttp1Backpressure method testBasicBackpressureChunked.
@Test
public void testBasicBackpressureChunked() throws InterruptedException, ExecutionException, TimeoutException {
MockResponseListener listener = new MockResponseListener();
RequestStreamHandle handle = socket.openStream();
mockChannel.addWriteResponse(XFuture.completedFuture(null));
Http2Request request = Requests.createRequest();
StreamRef streamRef = handle.process(request, listener);
XFuture<StreamWriter> writer = streamRef.getWriter();
Assert.assertTrue(writer.isDone());
Assert.assertEquals(request, mockChannel.getLastWriteParam());
Http2Response response1 = Requests.createChunkedResponse(1);
HttpChunk response2 = Requests.createHttpChunk(250);
HttpLastChunk lastChunk = new HttpLastChunk();
List<ByteBuffer> buffers = create4BuffersWith3Messags(response1, response2, lastChunk);
DataListener dataListener = mockChannel.getConnectedListener();
XFuture<Void> fut1 = dataListener.incomingData(mockChannel, buffers.get(0));
// resolved since it never made it to the client.
Assert.assertTrue(fut1.isDone());
// this keeps bytes in-memory that is less than bufPool.getSuggestedSize. ie. < 5k
XFuture<StreamWriter> requestFuture = new XFuture<StreamWriter>();
listener.addProcessResponse(requestFuture);
XFuture<Void> fut2 = dataListener.incomingData(mockChannel, buffers.get(1));
// not resolved yet since client only has part of the data
Assert.assertFalse(fut2.isDone());
XFuture<Void> streamWriterFuture = new XFuture<Void>();
MockStreamWriter mockWriter = new MockStreamWriter();
mockWriter.addProcessResponse(streamWriterFuture);
// This releases the response BUT 'some' data was with response so can't ack yet
requestFuture.complete(mockWriter);
// not resolved yet since requestFuture AND streamWriterFutuer BOTH need to be resolved
Assert.assertFalse(fut2.isDone());
// This is BECAUSE 68 bytes resulted in TWO messages and both futures can ack the 68 bytes.
streamWriterFuture.complete(null);
// NOW it's resolved
fut2.get(2, TimeUnit.SECONDS);
// feed the rest of first chunk in and feed part of last chunk
XFuture<Void> firstChunkAck = new XFuture<Void>();
mockWriter.addProcessResponse(firstChunkAck);
XFuture<Void> fut3 = dataListener.incomingData(mockChannel, buffers.get(2));
Assert.assertFalse(fut3.isDone());
// ack the http chunk packet
firstChunkAck.complete(null);
fut3.get(2, TimeUnit.SECONDS);
XFuture<Void> lastChunkAck = new XFuture<Void>();
mockWriter.addProcessResponse(lastChunkAck);
XFuture<Void> fut4 = dataListener.incomingData(mockChannel, buffers.get(3));
Assert.assertFalse(fut4.isDone());
lastChunkAck.complete(null);
fut4.get(2, TimeUnit.SECONDS);
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class Http2ToHttp11 method translateRequest.
public static HttpRequest translateRequest(Http2Request headers) {
HttpRequestLine requestLine = new HttpRequestLine();
HttpRequest req = new HttpRequest();
req.setRequestLine(requestLine);
for (Http2Header header : headers.getHeaders()) {
insertInfo(req, header);
}
Http2HeaderStruct headerMap = headers.getHeaderLookupStruct();
Http2Header method = headerMap.getHeader(Http2HeaderName.METHOD);
if (method == null)
throw new IllegalArgumentException(Http2HeaderName.METHOD.name() + "is a required header to translate to http1");
req.getRequestLine().setMethod(new HttpRequestMethod(method.getValue()));
Http2Header host = headerMap.getHeader(Http2HeaderName.AUTHORITY);
if (host == null)
throw new IllegalArgumentException(Http2HeaderName.AUTHORITY.name() + "is a required header to translate to http1");
Http2Header path = headerMap.getHeader(Http2HeaderName.PATH);
if (path == null)
throw new IllegalArgumentException(Http2HeaderName.PATH.name() + "is a required header to translate to http1");
HttpUri httpUri = new HttpUri(path.getValue());
req.getRequestLine().setUri(httpUri);
return req;
}
use of com.webpieces.http2.api.dto.highlevel.Http2Request in project webpieces by deanhiller.
the class AbstractFrontendHttp2Test method sendRequestToServer.
protected PassedIn sendRequestToServer(int streamId, boolean eos) {
Http2Request request1 = Http2Requests.createRequest(streamId, eos);
mockChannel.send(request1);
PassedIn req = mockListener.getSingleRequest();
Assert.assertEquals(request1, req.request);
return req;
}
Aggregations