use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class Preface method verify.
public void verify() {
buffer.flip();
DataWrapper data = dataGen.wrapByteBuffer(buffer);
String content = data.createStringFromUtf8(0, data.getReadableSize());
if (!"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n".equals(content))
throw new IllegalStateException("preface incorrect=" + content);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class DataWrapperGeneratorImpl method splitChainedWrapper.
private List<DataWrapper> splitChainedWrapper(ChainedDataWrapper dataToRead, int splitAtPosition) {
List<SliceableDataWrapper> wrappersInBegin = new ArrayList<>();
List<SliceableDataWrapper> wrappersInEnd = new ArrayList<>();
boolean foundSplit = false;
List<SliceableDataWrapper> splitBuffers = null;
for (SliceableDataWrapper wrapper : dataToRead.getWrappers()) {
if (!foundSplit) {
if (splitAtPosition == wrapper.getReadableSize()) {
wrappersInBegin.add(wrapper);
foundSplit = true;
} else if (splitAtPosition < wrapper.getReadableSize()) {
splitBuffers = splitSliceableWrapper(wrapper, splitAtPosition);
wrappersInBegin.add(splitBuffers.get(0));
wrappersInEnd.add(splitBuffers.get(1));
foundSplit = true;
} else {
wrappersInBegin.add(wrapper);
splitAtPosition = splitAtPosition - wrapper.getReadableSize();
}
} else {
wrappersInEnd.add(wrapper);
}
}
DataWrapper wrapper1;
if (wrappersInBegin.size() > 0)
wrapper1 = new ChainedDataWrapper(wrappersInBegin);
else
wrapper1 = EMPTY_WRAPPER;
DataWrapper wrapper2;
if (wrappersInEnd.size() > 0)
wrapper2 = new ChainedDataWrapper(wrappersInEnd);
else
wrapper2 = EMPTY_WRAPPER;
List<DataWrapper> finalTwo = new ArrayList<>();
finalTwo.add(wrapper1);
finalTwo.add(wrapper2);
return finalTwo;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class RecorderImpl method recordImpl.
public void recordImpl(ByteBuffer b) throws IOException {
DataWrapper wrapper = gen.wrapByteBuffer(b);
int size = wrapper.getReadableSize();
ByteBuffer sizeBuf = ByteBuffer.allocate(4);
sizeBuf.putInt(size);
sizeBuf.flip();
channel.write(sizeBuf);
ByteBuffer shallowCopy = b.duplicate();
channel.write(shallowCopy);
byte[] data = new byte[] { 0, 1, 2, 3, 4, 5, 6 };
ByteBuffer trailer = ByteBuffer.wrap(data);
channel.write(trailer);
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class ChainedDataWrapper method createByteArray.
@Override
public byte[] createByteArray() {
byte[] copy = new byte[getReadableSize()];
int offset = 0;
for (DataWrapper wrapper : wrappers) {
byte[] data = wrapper.createByteArray();
int size = wrapper.getReadableSize();
System.arraycopy(data, 0, copy, offset, size);
offset += size;
}
return copy;
}
use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.
the class TestHttp11Basic method testSendTwoRequestsStreamFirst.
@Test
public void testSendTwoRequestsStreamFirst() throws InterruptedException, ExecutionException {
HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
req.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "20"));
mockChannel.write(req);
PassedIn in1 = mockListener.getSingleRequest();
byte[] buf = new byte[10];
DataWrapper dataWrapper = dataGen.wrapByteArray(buf);
HttpData data1 = new HttpData(dataWrapper, false);
mockChannel.write(data1);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
DataWrapper dataWrapper2 = dataGen.wrapByteArray(buf);
HttpData data2 = new HttpData(dataWrapper2, true);
mockChannel.write(data2);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
mockChannel.write(req2);
Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
//send back request2's response first!!!! BUT verify it does not go to client per http11 pipelining rules
HttpResponse resp1 = Requests.createResponse(1);
resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
Http2Response headers1 = Http2Translations.responseToHeaders(resp1);
in1.stream.sendResponse(headers1);
HttpPayload payload = mockChannel.getFrameAndClear();
Assert.assertEquals(resp1, payload);
PassedIn in2 = mockListener.getSingleRequest();
HttpResponse resp2 = Requests.createResponse(2);
resp2.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "0"));
Http2Response headers2 = Http2Translations.responseToHeaders(resp2);
in2.stream.sendResponse(headers2);
HttpPayload payload2 = mockChannel.getFrameAndClear();
Assert.assertEquals(resp2, payload2);
}
Aggregations