Search in sources :

Example 41 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class HpackParserImpl method combineAndSendHeadersToClient.

private void combineAndSendHeadersToClient(UnmarshalStateImpl state) {
    List<HasHeaderFragment> hasHeaderFragmentList = state.getHeadersToCombine();
    // Now we set the full header list on the first frame and just return that
    HasHeaderFragment firstFrame = hasHeaderFragmentList.get(0);
    DataWrapper allSerializedHeaders = dataGen.emptyWrapper();
    for (HasHeaderFragment iterFrame : hasHeaderFragmentList) {
        allSerializedHeaders = dataGen.chainDataWrappers(allSerializedHeaders, iterFrame.getHeaderFragment());
    }
    Map<Http2HeaderName, Http2Header> knownHeaders = new HashMap<>();
    List<Http2Header> headers = decoding.decode(state, allSerializedHeaders, firstFrame.getStreamId(), header -> knownHeaders.put(header.getKnownName(), header));
    if (firstFrame instanceof HeadersFrame) {
        HeadersFrame f = (HeadersFrame) firstFrame;
        Http2Headers fullHeaders = createCorrectType(knownHeaders, headers, state.getLogId(), f.getStreamId());
        fullHeaders.setStreamId(f.getStreamId());
        fullHeaders.setPriorityDetails(f.getPriorityDetails());
        fullHeaders.setEndOfStream(f.isEndOfStream());
        state.getParsedFrames().add(fullHeaders);
    } else if (firstFrame instanceof PushPromiseFrame) {
        PushPromiseFrame f = (PushPromiseFrame) firstFrame;
        Http2Push fullHeaders = new Http2Push(headers);
        fullHeaders.setStreamId(f.getStreamId());
        fullHeaders.setPromisedStreamId(f.getPromisedStreamId());
        state.getParsedFrames().add(fullHeaders);
    }
    hasHeaderFragmentList.clear();
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HasHeaderFragment(com.webpieces.http2parser.api.dto.lib.HasHeaderFragment) HashMap(java.util.HashMap) Http2Headers(com.webpieces.hpack.api.dto.Http2Headers) Http2HeaderName(com.webpieces.http2parser.api.dto.lib.Http2HeaderName) Http2Header(com.webpieces.http2parser.api.dto.lib.Http2Header) Http2Push(com.webpieces.hpack.api.dto.Http2Push) PushPromiseFrame(com.webpieces.http2parser.api.dto.PushPromiseFrame) HeadersFrame(com.webpieces.http2parser.api.dto.HeadersFrame)

Example 42 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class PaddingUtil method padDataIfNeeded.

public static DataWrapper padDataIfNeeded(DataWrapper data, DataWrapper padding) {
    if (padding.getReadableSize() > 0) {
        byte[] length = { (byte) padding.getReadableSize() };
        DataWrapper lengthDW = dataGen.wrapByteArray(length);
        return dataGen.chainDataWrappers(dataGen.chainDataWrappers(lengthDW, data), padding);
    } else
        return data;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper)

Example 43 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class DataWrapperGeneratorImpl method chainDataWrappers.

@Override
public DataWrapper chainDataWrappers(DataWrapper firstData, ByteBuffer... secondData) {
    DataWrapper wrapper = firstData;
    for (ByteBuffer buffer : secondData) {
        DataWrapper second = wrapByteBuffer(buffer);
        wrapper = chainDataWrappers(wrapper, second);
    }
    return wrapper;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer)

Example 44 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class ChainedDataWrapper method readByteAt.

@Override
public byte readByteAt(int i) {
    int j = i;
    for (DataWrapper wrapper : wrappers) {
        int size = wrapper.getReadableSize();
        if (j < size) {
            return wrapper.readByteAt(j);
        }
        j = j - size;
    }
    throw new IndexOutOfBoundsException("i=" + i + " is out of bounds of size=" + getReadableSize());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper)

Example 45 with DataWrapper

use of org.webpieces.data.api.DataWrapper in project webpieces by deanhiller.

the class ChainedDataWrapper method createStringFrom.

@Override
public String createStringFrom(int initialOffset, int length, Charset charSet) {
    if (length == 0)
        return "";
    String result = "";
    int lengthLeftToRead = length;
    int offset = initialOffset;
    for (DataWrapper wrapper : wrappers) {
        int size = wrapper.getReadableSize();
        if (offset < size) {
            if (offset + lengthLeftToRead <= size) {
                result += wrapper.createStringFrom(offset, lengthLeftToRead, charSet);
                return result;
            }
            int leftInBuffer = size - offset;
            result += wrapper.createStringFrom(offset, leftInBuffer, charSet);
            //since we read in this data, offset for next datawrapper is 0
            offset = 0;
            lengthLeftToRead -= leftInBuffer;
        } else {
            offset -= size;
        }
    }
    throw new IndexOutOfBoundsException("offset=" + offset + " length=" + length + " is larger than size=" + getReadableSize());
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper)

Aggregations

DataWrapper (org.webpieces.data.api.DataWrapper)115 Test (org.junit.Test)47 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)22 ByteBuffer (java.nio.ByteBuffer)20 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)18 Header (org.webpieces.httpparser.api.common.Header)17 HttpPayload (org.webpieces.httpparser.api.dto.HttpPayload)17 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)16 HttpData (org.webpieces.httpparser.api.dto.HttpData)15 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)12 Http2Request (com.webpieces.hpack.api.dto.Http2Request)10 StreamWriter (com.webpieces.http2engine.api.StreamWriter)8 PassedIn (org.webpieces.httpfrontend2.api.mock2.MockHttp2RequestListener.PassedIn)8 MockResponseListener (org.webpieces.http2client.mock.MockResponseListener)7 HttpChunk (org.webpieces.httpparser.api.dto.HttpChunk)7 Http2Response (com.webpieces.hpack.api.dto.Http2Response)6 ConnectionClosedException (com.webpieces.http2engine.api.ConnectionClosedException)6 ArrayList (java.util.ArrayList)6 ShutdownStream (com.webpieces.http2engine.api.error.ShutdownStream)5 ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)5