Search in sources :

Example 36 with DataWrapper

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

the class Http2ParserImpl method parseFrameHeader.

/**
	 * Return true if header was parsed
	 * @param maxFrameSize 
	 */
private boolean parseFrameHeader(Http2MementoImpl state) {
    DataWrapper allData = state.getLeftOverData();
    int lengthOfData = allData.getReadableSize();
    if (lengthOfData < 9) {
        // Not even a frame header
        state.setLeftOverData(allData);
        return false;
    }
    List<? extends DataWrapper> split = dataGen.split(allData, 9);
    DataWrapper frameHeader = split.get(0);
    DataWrapper left = split.get(1);
    int payloadLength = getLength(frameHeader);
    int streamId = getStreamId(frameHeader);
    byte frameTypeId = frameHeader.readByteAt(3);
    byte flagsByte = frameHeader.readByteAt(4);
    long maxFrameSize = state.getIncomingMaxFrameSize();
    if (payloadLength > maxFrameSize)
        throw new ConnectionException(CancelReasonCode.EXCEEDED_MAX_FRAME_SIZE, streamId, "Frame size=" + payloadLength + " was greater than max=" + maxFrameSize);
    state.setFrameHeaderData(new FrameHeaderData(payloadLength, streamId, frameTypeId, flagsByte));
    state.setLeftOverData(left);
    return true;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 37 with DataWrapper

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

the class SettingsMarshaller method marshalPayload.

public String marshalPayload(List<Http2Setting> settingsPayload) {
    DataWrapper data = marshalOut(settingsPayload);
    byte[] byteBuf = data.createByteArray();
    Encoder encoder = Base64.getEncoder();
    return encoder.encodeToString(byteBuf);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Encoder(java.util.Base64.Encoder)

Example 38 with DataWrapper

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

the class WindowUpdateMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    WindowUpdateFrame castFrame = (WindowUpdateFrame) frame;
    ByteBuffer payload = bufferPool.nextBuffer(4).putInt(castFrame.getWindowSizeIncrement());
    payload.flip();
    DataWrapper dataPayload = dataGen.wrapByteBuffer(payload);
    return super.marshalFrame(frame, (byte) 0, dataPayload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) WindowUpdateFrame(com.webpieces.http2parser.api.dto.WindowUpdateFrame) ByteBuffer(java.nio.ByteBuffer)

Example 39 with DataWrapper

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

the class HeadersMarshaller method unmarshal.

@Override
public AbstractHttp2Frame unmarshal(Http2MementoImpl state, DataWrapper framePayloadData) {
    HeadersFrame frame = new HeadersFrame();
    super.unmarshalFrame(state, frame);
    byte flagsByte = state.getFrameHeaderData().getFlagsByte();
    frame.setEndOfStream((flagsByte & 0x1) == 0x1);
    frame.setEndHeaders((flagsByte & 0x4) == 0x4);
    boolean isPadded = (flagsByte & 0x8) == 0x8;
    PriorityDetails priorityDetails = null;
    if ((flagsByte & 0x20) == 0x20) {
        priorityDetails = new PriorityDetails();
        frame.setPriorityDetails(priorityDetails);
    }
    DataSplit padSplit = PaddingUtil.extractPayloadAndPadding(isPadded, framePayloadData, frame.getStreamId());
    frame.setPadding(padSplit.getPadding());
    DataWrapper paddingStripped = padSplit.getPayload();
    if (priorityDetails != null) {
        //1 bit Exclusive flag, 31 bits stream dependency, and 8 bits weight = 5 bytes....
        List<? extends DataWrapper> split = dataGen.split(paddingStripped, 5);
        ByteBuffer preludeBytes = bufferPool.createWithDataWrapper(split.get(0));
        int firstInt = preludeBytes.getInt();
        priorityDetails.setStreamDependencyIsExclusive((firstInt >>> 31) == 0x1);
        int streamDependency = firstInt & 0x7FFFFFFF;
        if (streamDependency == frame.getStreamId()) {
            // Can't depend on self
            throw new ConnectionException(CancelReasonCode.BAD_STREAM_DEPENDENCY, streamDependency, "stream id=" + streamDependency + " depends on itself");
        }
        priorityDetails.setStreamDependency(streamDependency);
        priorityDetails.setWeight((short) (preludeBytes.get() & 0xFF));
        frame.setHeaderFragment(split.get(1));
        bufferPool.releaseBuffer(preludeBytes);
    } else {
        frame.setHeaderFragment(paddingStripped);
    }
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "headers frame had invalid stream id=" + frame.getStreamId());
    return frame;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2parser.api.dto.lib.PriorityDetails) HeadersFrame(com.webpieces.http2parser.api.dto.HeadersFrame) ByteBuffer(java.nio.ByteBuffer) DataSplit(com.webpieces.http2parser.impl.DataSplit) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 40 with DataWrapper

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

the class HeadersMarshaller method marshal.

@Override
public DataWrapper marshal(Http2Frame frame) {
    HeadersFrame castFrame = (HeadersFrame) frame;
    if (frame.getStreamId() == 0)
        throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, frame.getStreamId(), "Headers frame cannot be streamId 0");
    int paddingSize = castFrame.getPadding().getReadableSize();
    byte value = 0x0;
    if (castFrame.isEndOfStream())
        value |= 0x1;
    if (castFrame.isEndHeaders())
        value |= 0x4;
    if (paddingSize > 0)
        value |= 0x8;
    if (castFrame.isPriority())
        value |= 0x20;
    DataWrapper preludeDW;
    PriorityDetails priorityDetails = castFrame.getPriorityDetails();
    if (priorityDetails != null) {
        preludeDW = PriorityMarshaller.marshalPriorityDetails(bufferPool, priorityDetails, frame);
    } else {
        preludeDW = dataGen.emptyWrapper();
    }
    DataWrapper unpadded = dataGen.chainDataWrappers(preludeDW, castFrame.getHeaderFragment());
    DataWrapper payload = PaddingUtil.padDataIfNeeded(unpadded, castFrame.getPadding());
    return super.marshalFrame(frame, value, payload);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) PriorityDetails(com.webpieces.http2parser.api.dto.lib.PriorityDetails) HeadersFrame(com.webpieces.http2parser.api.dto.HeadersFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

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