Search in sources :

Example 11 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class Level8NotifyClntListeners method sendPieceToApp.

@Override
public CompletableFuture<Void> sendPieceToApp(Stream stream, StreamMsg payload) {
    ClientStream str = (ClientStream) stream;
    StreamWriter writer = str.getResponseWriter();
    return writer.processPiece(payload).thenApply(s -> null);
}
Also used : StreamWriter(com.webpieces.http2engine.api.StreamWriter)

Example 12 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class Level8NotifySvrListeners method sendPieceToApp.

@Override
public CompletableFuture<Void> sendPieceToApp(Stream stream, StreamMsg payload) {
    ServerStream s = (ServerStream) stream;
    StreamWriter writer = s.getStreamWriter();
    return writer.processPiece(payload).thenApply(v -> null);
}
Also used : StreamWriter(com.webpieces.http2engine.api.StreamWriter)

Example 13 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class TestHttp11Basic method testSendTwoRequestsStreamFirstResponse.

@Test
public void testSendTwoRequestsStreamFirstResponse() throws InterruptedException, ExecutionException, TimeoutException {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    HttpRequest req2 = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    mockChannel.write(req);
    PassedIn in1 = mockListener.getSingleRequest();
    mockChannel.write(req2);
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    HttpResponse resp1 = Requests.createResponse(1);
    resp1.addHeader(new Header(KnownHeaderName.CONTENT_LENGTH, "10"));
    Http2Response headers1 = Http2Translations.responseToHeaders(resp1);
    CompletableFuture<StreamWriter> future = in1.stream.sendResponse(headers1);
    HttpPayload payload = mockChannel.getFrameAndClear();
    Assert.assertEquals(resp1, payload);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    Assert.assertEquals(0, mockListener.getNumRequestsThatCameIn());
    byte[] buf = new byte[10];
    DataWrapper dataWrapper = dataGen.wrapByteArray(buf);
    HttpData data1 = new HttpData(dataWrapper, true);
    DataFrame data = (DataFrame) Http2Translations.translateData(data1);
    writer.processPiece(data);
    HttpData d = (HttpData) mockChannel.getFrameAndClear();
    Assert.assertEquals(10, d.getBody().getReadableSize());
    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);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) Http2Response(com.webpieces.hpack.api.dto.Http2Response) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpData(org.webpieces.httpparser.api.dto.HttpData) StreamWriter(com.webpieces.http2engine.api.StreamWriter) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) Test(org.junit.Test)

Example 14 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class TestHttp11Basic method testFileDownloadWithChunking.

@Test
public void testFileDownloadWithChunking() throws InterruptedException, ExecutionException, TimeoutException {
    HttpRequest req = Requests.createRequest(KnownHttpMethod.GET, "/xxxx");
    mockChannel.write(req);
    PassedIn in1 = mockListener.getSingleRequest();
    HttpRequest req1 = Http2Translations.translateRequest(in1.request);
    Assert.assertEquals(req, req1);
    HttpResponse resp = Requests.createResponse();
    resp.addHeader(new Header(KnownHeaderName.TRANSFER_ENCODING, "chunked"));
    Http2Response headers = Http2Translations.responseToHeaders(resp);
    CompletableFuture<StreamWriter> future = in1.stream.sendResponse(headers);
    HttpResponse respToClient = (HttpResponse) mockChannel.getFrameAndClear();
    Assert.assertEquals(resp, respToClient);
    StreamWriter writer = future.get(2, TimeUnit.SECONDS);
    DataFrame dataFrame = new DataFrame();
    dataFrame.setEndOfStream(true);
    String bodyStr = "hi here and there";
    DataWrapper data = dataGen.wrapByteArray(bodyStr.getBytes(StandardCharsets.UTF_8));
    dataFrame.setData(data);
    writer.processPiece(dataFrame);
    List<HttpPayload> frames = mockChannel.getFramesAndClear();
    Assert.assertEquals(2, frames.size());
    HttpChunk chunk = (HttpChunk) frames.get(0);
    DataWrapper body = chunk.getBodyNonNull();
    String result = body.createStringFromUtf8(0, body.getReadableSize());
    Assert.assertEquals(bodyStr, result);
    HttpLastChunk last = (HttpLastChunk) frames.get(1);
    Assert.assertEquals(0, last.getBodyNonNull().getReadableSize());
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Http2Response(com.webpieces.hpack.api.dto.Http2Response) StreamWriter(com.webpieces.http2engine.api.StreamWriter) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) PassedIn(org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn) DataWrapper(org.webpieces.data.api.DataWrapper) HttpLastChunk(org.webpieces.httpparser.api.dto.HttpLastChunk) Header(org.webpieces.httpparser.api.common.Header) HttpPayload(org.webpieces.httpparser.api.dto.HttpPayload) HttpChunk(org.webpieces.httpparser.api.dto.HttpChunk) Test(org.junit.Test)

Example 15 with StreamWriter

use of com.webpieces.http2engine.api.StreamWriter in project webpieces by deanhiller.

the class Layer2Http1_1Handler method processData.

private CompletableFuture<Void> processData(FrontendSocketImpl socket, DataFrame msg) {
    PermitQueue permitQueue = socket.getPermitQueue();
    return permitQueue.runRequest(() -> {
        Http1_1StreamImpl stream = socket.getCurrentStream();
        StreamWriter requestWriter = stream.getRequestWriter();
        if (msg.isEndOfStream())
            stream.setSentFullRequest(true);
        return requestWriter.processPiece(msg).thenApply(w -> {
            stream.setRequestWriter(w);
            if (!msg.isEndOfStream())
                permitQueue.releasePermit();
            return null;
        });
    });
}
Also used : PermitQueue(com.webpieces.util.locking.PermitQueue) StreamWriter(com.webpieces.http2engine.api.StreamWriter)

Aggregations

StreamWriter (com.webpieces.http2engine.api.StreamWriter)26 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)17 Test (org.junit.Test)16 Http2Response (com.webpieces.hpack.api.dto.Http2Response)13 Http2Request (com.webpieces.hpack.api.dto.Http2Request)12 DataWrapper (org.webpieces.data.api.DataWrapper)9 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)8 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)8 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)5 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)5 Header (org.webpieces.httpparser.api.common.Header)4 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)4 Http2Header (com.webpieces.http2parser.api.dto.lib.Http2Header)3 Http2HeaderName (com.webpieces.http2parser.api.dto.lib.Http2HeaderName)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ResponseStream (org.webpieces.frontend2.api.ResponseStream)3 MockStreamWriter (org.webpieces.httpfrontend2.api.mock2.MockStreamWriter)3 HttpData (org.webpieces.httpparser.api.dto.HttpData)3