Search in sources :

Example 41 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class NullWriter method processPiece.

@Override
public XFuture<Void> processPiece(StreamMsg data) {
    DataFrame f = (DataFrame) data;
    DataWrapper body = f.getData();
    String str = body.createStringFromUtf8(0, body.getReadableSize());
    log.error("Should not be receiving data(len=" + body.getReadableSize() + ").  data Received=" + str, new RuntimeException("Received data here and should not").fillInStackTrace());
    return XFuture.completedFuture(null);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame)

Example 42 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class XFileReader method sendHttpChunk.

private XFuture<Void> sendHttpChunk(StreamWriter writer, BufferPool pool, ByteBuffer buf, boolean isEos) {
    DataWrapper data = wrapperFactory.wrapByteBuffer(buf);
    int len = data.getReadableSize();
    if (log.isTraceEnabled())
        log.trace("SENDING data to=" + writer + " len=" + len + " isEnd=" + isEos + " content=" + data.createStringFromUtf8(0, len));
    DataFrame frame = new DataFrame();
    frame.setEndOfStream(isEos);
    frame.setData(data);
    return writer.processPiece(frame).thenApply(w -> {
        // at this point, the buffer was consumed
        // after process, release the buffer for re-use
        buf.position(buf.limit());
        pool.releaseBuffer(buf);
        return null;
    });
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame)

Example 43 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class ProxyStreamHandle method createFrame.

private CompletionStage<Void> createFrame(byte[] bytes, StreamWriter writer) {
    DataFrame frame = new DataFrame();
    frame.setEndOfStream(true);
    frame.setData(dataGen.wrapByteArray(bytes));
    return writer.processPiece(frame);
}
Also used : DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame)

Example 44 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class RequestStreamWriter2 method processPiece.

@Override
public XFuture<Void> processPiece(StreamMsg frame) {
    if (cancelled) {
        return XFuture.completedFuture(null);
    } else if (frame instanceof CancelReason) {
        cancelled = true;
        responseFuture.cancel(true);
    } else if (frame instanceof DataFrame) {
        DataFrame dataFrame = (DataFrame) frame;
        data = dataGen.chainDataWrappers(data, dataFrame.getData());
    } else if (frame instanceof Http2Headers) {
        if (!frame.isEndOfStream())
            throw new IllegalArgumentException("Trailing headers from client must have end of stream set");
        trailingHeaders = (Http2Headers) frame;
    } else {
        throw new IllegalStateException("frame not expected=" + frame);
    }
    if (frame.isEndOfStream()) {
        return handleCompleteRequestImpl();
    }
    // return immediately resolved as we need more data to form request
    return XFuture.completedFuture(null);
}
Also used : CancelReason(com.webpieces.http2.api.dto.lowlevel.CancelReason) Http2Headers(com.webpieces.http2.api.dto.highlevel.Http2Headers) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame)

Example 45 with DataFrame

use of com.webpieces.http2.api.dto.lowlevel.DataFrame in project webpieces by deanhiller.

the class TestC4FrameSizeAndHeaders method testSection4_2CanSendLargestFrame.

/**
 * success case of edge testing off by one or not
 */
@Test
public void testSection4_2CanSendLargestFrame() {
    MockStreamWriter mockStreamWriter = new MockStreamWriter();
    MockResponseListener listener1 = new MockResponseListener();
    listener1.setIncomingRespDefault(XFuture.<StreamWriter>completedFuture(mockStreamWriter));
    Http2Request request = sendRequestToServer(listener1);
    sendResponseFromServer(listener1, request);
    DataFrame dataFrame = new DataFrame(request.getStreamId(), false);
    byte[] buf = new byte[localSettings.getMaxFrameSize()];
    dataFrame.setData(DATA_GEN.wrapByteArray(buf));
    // endOfStream=false
    mockChannel.write(dataFrame);
    DataFrame fr = (DataFrame) mockStreamWriter.getSingleFrame();
    Assert.assertEquals(localSettings.getMaxFrameSize(), fr.getData().getReadableSize());
}
Also used : Http2Request(com.webpieces.http2.api.dto.highlevel.Http2Request) MockResponseListener(org.webpieces.http2client.mock.MockResponseListener) DataFrame(com.webpieces.http2.api.dto.lowlevel.DataFrame) MockStreamWriter(org.webpieces.http2client.mock.MockStreamWriter) Test(org.junit.Test)

Aggregations

DataFrame (com.webpieces.http2.api.dto.lowlevel.DataFrame)52 Test (org.junit.Test)31 DataWrapper (org.webpieces.data.api.DataWrapper)28 StreamWriter (com.webpieces.http2.api.streaming.StreamWriter)19 Http2Request (com.webpieces.http2.api.dto.highlevel.Http2Request)13 Http2Response (com.webpieces.http2.api.dto.highlevel.Http2Response)11 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)9 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)9 GoAwayFrame (com.webpieces.http2.api.dto.lowlevel.GoAwayFrame)8 Http2Msg (com.webpieces.http2.api.dto.lowlevel.lib.Http2Msg)8 MockStreamWriter (org.webpieces.http2client.mock.MockStreamWriter)7 StreamRef (com.webpieces.http2.api.streaming.StreamRef)6 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)6 ConnectionClosedException (com.webpieces.http2engine.api.error.ConnectionClosedException)5 Header (org.webpieces.httpparser.api.common.Header)5 Http2Headers (com.webpieces.http2.api.dto.highlevel.Http2Headers)4 HttpData (org.webpieces.httpparser.api.dto.HttpData)4 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)4 ConnectionException (com.webpieces.http2.api.dto.error.ConnectionException)3 Http2Push (com.webpieces.http2.api.dto.highlevel.Http2Push)3