Search in sources :

Example 16 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.

the class MockHttp1Channel method write.

@SuppressWarnings("unchecked")
@Override
public XFuture<Void> write(ByteBuffer b) {
    DataWrapper data = dataGen.wrapByteBuffer(b);
    parser.parse(memento, data);
    List<HttpPayload> payloads = memento.getParsedMessages();
    return (XFuture<Void>) super.calledMethod(Method.INCOMING_FRAME, payloads);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) XFuture(org.webpieces.util.futures.XFuture)

Example 17 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.

the class Layer2Http1_1Handler method processHttp1MessagesImpl.

private CompletableFuture<Void> processHttp1MessagesImpl(FrontendSocketImpl socket, Memento state) {
    List<HttpPayload> parsed = state.getParsedMessages();
    CompletableFuture<Void> future = CompletableFuture.completedFuture(null);
    for (HttpPayload payload : parsed) {
        future = future.thenCompose(w -> {
            log.info("msg received=" + payload);
            return processCorrectly(socket, payload);
        });
    }
    return future.thenApply(w -> null);
}
Also used : Logger(org.webpieces.util.logging.Logger) MarshalState(org.webpieces.httpparser.api.MarshalState) PermitQueue(com.webpieces.util.locking.PermitQueue) Http2Translations(org.webpieces.frontend2.impl.translation.Http2Translations) HttpParser(org.webpieces.httpparser.api.HttpParser) CompletableFuture(java.util.concurrent.CompletableFuture) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) ByteBuffer(java.nio.ByteBuffer) StreamListener(org.webpieces.frontend2.api.StreamListener) Http2HeaderName(com.webpieces.http2parser.api.dto.lib.Http2HeaderName) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) Memento(org.webpieces.httpparser.api.Memento) List(java.util.List) HttpStream(org.webpieces.frontend2.api.HttpStream) StreamWriter(com.webpieces.http2engine.api.StreamWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Http2Request(com.webpieces.hpack.api.dto.Http2Request) DataWrapper(org.webpieces.data.api.DataWrapper) DataWrapperGenerator(org.webpieces.data.api.DataWrapperGenerator) LoggerFactory(org.webpieces.util.logging.LoggerFactory) HttpMessageType(org.webpieces.httpparser.api.dto.HttpMessageType) DataWrapperGeneratorFactory(org.webpieces.data.api.DataWrapperGeneratorFactory) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload)

Example 18 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.

the class TestChunkedParsing method testBasic.

@Test
public void testBasic() {
    String chunkedData = "4\r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n";
    HttpResponse resp = TestResponseParsing.createOkResponse();
    resp.addHeader(new Header(KnownHeaderName.TRANSFER_ENCODING, "chunked"));
    byte[] bytes = unwrap(parser.marshalToByteBuffer(state, resp));
    byte[] chunked = chunkedData.getBytes();
    byte[] all = new byte[bytes.length + chunked.length];
    System.arraycopy(bytes, 0, all, 0, bytes.length);
    System.arraycopy(chunked, 0, all, bytes.length, chunked.length);
    DataWrapper wrapper = dataGen.wrapByteArray(all);
    Memento memento = parser.prepareToParse();
    memento = parser.parse(memento, wrapper);
    List<HttpPayload> msgs = memento.getParsedMessages();
    Assert.assertEquals(5, msgs.size());
    HttpPayload msg = msgs.get(0).getHttpResponse();
    Assert.assertEquals(resp, msg);
    HttpChunk chunk1 = msgs.get(1).getHttpChunk();
    String first = chunk1.getBody().createStringFrom(0, chunk1.getBody().getReadableSize(), Charset.defaultCharset());
    Assert.assertEquals("Wiki", first);
    HttpChunk chunk3 = msgs.get(3).getHttpChunk();
    String third = chunk3.getBody().createStringFrom(0, chunk3.getBody().getReadableSize(), Charset.defaultCharset());
    Assert.assertEquals(" in\r\n\r\nchunks.", third);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpChunk(org.webpieces.httpparser.api.dto.HttpChunk) Test(org.junit.Test)

Example 19 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.

the class TestChunkedParsing method testResponseAfterChunked.

@Test
public void testResponseAfterChunked() {
    String chunkedData = "4\r\nWiki\r\n5\r\npedia\r\nE\r\n in\r\n\r\nchunks.\r\n0\r\n\r\n";
    HttpResponse resp = TestResponseParsing.createOkResponse();
    resp.addHeader(new Header(KnownHeaderName.TRANSFER_ENCODING, "chunked"));
    byte[] bytes = unwrap(parser.marshalToByteBuffer(state, resp));
    byte[] chunked = chunkedData.getBytes();
    HttpResponse resp400 = create400Response();
    byte[] tail = unwrap(parser.marshalToByteBuffer(state, resp400));
    byte[] all = new byte[bytes.length + chunked.length + tail.length];
    System.arraycopy(bytes, 0, all, 0, bytes.length);
    System.arraycopy(chunked, 0, all, bytes.length, chunked.length);
    System.arraycopy(tail, 0, all, bytes.length + chunked.length, tail.length);
    DataWrapper wrapper = dataGen.wrapByteArray(all);
    Memento memento = parser.prepareToParse();
    memento = parser.parse(memento, wrapper);
    List<HttpPayload> msgs = memento.getParsedMessages();
    Assert.assertEquals(6, msgs.size());
    HttpPayload msg = msgs.get(0).getHttpResponse();
    Assert.assertEquals(resp, msg);
    HttpChunk chunk1 = msgs.get(1).getHttpChunk();
    String first = chunk1.getBody().createStringFrom(0, chunk1.getBody().getReadableSize(), Charset.defaultCharset());
    Assert.assertEquals("Wiki", first);
    HttpChunk chunk3 = msgs.get(3).getHttpChunk();
    String third = chunk3.getBody().createStringFrom(0, chunk3.getBody().getReadableSize(), Charset.defaultCharset());
    Assert.assertEquals(" in\r\n\r\nchunks.", third);
    HttpPayload tailMsg = msgs.get(5);
    Assert.assertEquals(resp400, tailMsg);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpChunk(org.webpieces.httpparser.api.dto.HttpChunk) Test(org.junit.Test)

Example 20 with HttpPayload

use of org.webpieces.httpparser.api.dto.HttpPayload in project webpieces by deanhiller.

the class TestChunkedParsing method testSplitChunkBodyAndResponseAfter.

@Test
public void testSplitChunkBodyAndResponseAfter() {
    String chunkedData = "1E\r\n012345678901234567890123456789\r\n7\r\nchunks.\r\n0\r\n\r\n";
    HttpResponse resp = TestResponseParsing.createOkResponse();
    resp.addHeader(new Header(KnownHeaderName.TRANSFER_ENCODING, "chunked"));
    byte[] bytes = unwrap(parser.marshalToByteBuffer(state, resp));
    byte[] chunked = chunkedData.getBytes();
    HttpResponse resp400 = create400Response();
    byte[] tail = unwrap(parser.marshalToByteBuffer(state, resp400));
    int lengthOfChunked1stHalf = 15;
    int lengthOfChunked2ndHalf = chunked.length - 15;
    byte[] firstPiece = new byte[bytes.length + lengthOfChunked1stHalf];
    byte[] secondPiece = new byte[chunked.length - lengthOfChunked1stHalf + tail.length];
    System.arraycopy(bytes, 0, firstPiece, 0, bytes.length);
    System.arraycopy(chunked, 0, firstPiece, bytes.length, lengthOfChunked1stHalf);
    System.arraycopy(chunked, lengthOfChunked1stHalf, secondPiece, 0, lengthOfChunked2ndHalf);
    System.arraycopy(tail, 0, secondPiece, lengthOfChunked2ndHalf, tail.length);
    DataWrapper first = dataGen.wrapByteArray(firstPiece);
    DataWrapper second = dataGen.wrapByteArray(secondPiece);
    Memento memento = parser.prepareToParse();
    memento = parser.parse(memento, first);
    Assert.assertEquals(ParsingState.CHUNK, memento.getUnParsedState().getCurrentlyParsing());
    Assert.assertEquals(11, memento.getUnParsedState().getCurrentUnparsedSize());
    List<HttpPayload> msgs = memento.getParsedMessages();
    Assert.assertEquals(1, msgs.size());
    Assert.assertEquals(resp, msgs.get(0));
    memento = parser.parse(memento, second);
    List<HttpPayload> parsedMessages = memento.getParsedMessages();
    Assert.assertEquals(4, parsedMessages.size());
    Assert.assertEquals(resp400, parsedMessages.get(3));
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) Test(org.junit.Test)

Aggregations

HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)35 DataWrapper (org.webpieces.data.api.DataWrapper)30 Test (org.junit.Test)24 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)23 Header (org.webpieces.httpparser.api.common.Header)18 HttpData (org.webpieces.httpparser.api.dto.HttpData)14 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)13 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)6 DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)4 HttpChunk (org.webpieces.httpparser.api.dto.HttpChunk)4 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)3 ByteBuffer (java.nio.ByteBuffer)3 Memento (org.webpieces.httpparser.api.Memento)3 HttpLastData (org.webpieces.httpparser.api.dto.HttpLastData)3 XFuture (org.webpieces.util.futures.XFuture)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2