use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class TestReceiveHttp2 method testReceivePreface.
@Test
public void testReceivePreface() {
// All the 1's must be ignored and in leftover data
String preface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n1111";
byte[] bytes = preface.getBytes(StandardCharsets.UTF_8);
DataWrapper moreData = dataGen.wrapByteArray(bytes);
Memento state = parser.prepareToParse();
state = parser.parse(state, moreData);
Assert.assertEquals(1, state.getParsedMessages().size());
Assert.assertEquals(4, state.getLeftOverData().getReadableSize());
HttpPayload httpPayload = state.getParsedMessages().get(0);
Assert.assertEquals(HttpMessageType.HTTP2_MARKER_MSG, httpPayload.getMessageType());
}
use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class TestRequestParsing method testPartialHttpMessage.
@Test
public void testPartialHttpMessage() {
HttpRequest request = createPostRequest();
byte[] payload = unwrap(parser.marshalToByteBuffer(state, request));
byte[] firstPart = new byte[10];
byte[] secondPart = new byte[payload.length - firstPart.length];
// let's split the payload up into two pieces
System.arraycopy(payload, 0, firstPart, 0, firstPart.length);
System.arraycopy(payload, firstPart.length, secondPart, 0, secondPart.length);
DataWrapper data1 = dataGen.wrapByteArray(firstPart);
DataWrapper data2 = dataGen.wrapByteArray(secondPart);
Memento memento = parser.prepareToParse();
memento = parser.parse(memento, data1);
Assert.assertEquals(0, memento.getParsedMessages().size());
memento = parser.parse(memento, data2);
Assert.assertEquals(1, memento.getParsedMessages().size());
HttpPayload httpMessage = memento.getParsedMessages().get(0);
HttpRequest req = (HttpRequest) httpMessage;
Assert.assertEquals(request.getRequestLine(), req.getRequestLine());
Assert.assertEquals(request.getHeaders(), req.getHeaders());
Assert.assertEquals(request, httpMessage);
}
use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class TestGooglePlayback method testHttpsGooglePlayback.
@Test
public void testHttpsGooglePlayback() {
List<HttpPayload> results = runPlayback("https.google.com.recording");
int size = 0;
for (HttpPayload result : results) {
if (result.getMessageType() != HttpMessageType.DATA)
continue;
size += result.getHttpData().getBodyNonNull().getReadableSize();
}
Assert.assertEquals(10396, size);
HttpResponse resp = (HttpResponse) results.get(0);
HttpLastData lastChunk = (HttpLastData) results.get(results.size() - 1);
Assert.assertEquals("chunked", resp.getHeaderLookupStruct().getHeader(KnownHeaderName.TRANSFER_ENCODING).getValue());
Assert.assertTrue(lastChunk.isEndOfData());
}
use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class TestGooglePlayback method runPlayback.
private List<HttpPayload> runPlayback(String name) {
Memento mem = parser.prepareToParse();
int counter = 0;
ClassLoader cl = getClass().getClassLoader();
InputStream in = cl.getResourceAsStream(name);
// This loads relative to this test class package(while the above does not).
// InputStream in = getClass().getResourceAsStream(name);
Playback playback = RecordingPlaybackFactory.createPlayback(in, 1);
List<HttpPayload> results = new ArrayList<>();
while (true) {
counter++;
if (counter > 1000)
throw new IllegalArgumentException("Is your simulation really this long...1000+ buffers?");
ByteBuffer buffer = playback.getNextPacket();
if (buffer == null)
return results;
DataWrapper data = dataGen.wrapByteBuffer(buffer);
mem = parser.parse(mem, data);
List<HttpPayload> parsedMessages = mem.getParsedMessages();
results.addAll(parsedMessages);
}
}
use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.
the class TestGooglePlayback method testGooglePlayback.
@Test
public void testGooglePlayback() {
List<HttpPayload> results = runPlayback("google.com.11015.recording");
int size = 0;
for (HttpPayload result : results) {
if (result.getMessageType() != HttpMessageType.DATA)
continue;
size += result.getHttpData().getBodyNonNull().getReadableSize();
}
Assert.assertEquals(10349, size);
HttpResponse resp = (HttpResponse) results.get(0);
HttpLastData lastChunk = (HttpLastData) results.get(results.size() - 1);
Assert.assertEquals("chunked", resp.getHeaderLookupStruct().getHeader(KnownHeaderName.TRANSFER_ENCODING).getValue());
Assert.assertTrue(lastChunk.isEndOfData());
}
Aggregations