Search in sources :

Example 16 with DataWrapper

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

the class HttpParserImpl method processUntilRead.

/**
	 * Returns true if we split the buffers up or else false
	 */
private boolean processUntilRead(MementoImpl memento, int i) {
    DataWrapper dataToRead = memento.getLeftOverData();
    byte firstByte = dataToRead.readByteAt(i);
    byte secondByte = dataToRead.readByteAt(i + 1);
    byte thirdByte = dataToRead.readByteAt(i + 2);
    byte fourthByte = dataToRead.readByteAt(i + 3);
    //For debugging to see the 4 bytes that we are processing easier
    //		log.error("This should be commented out, don't forget or we log this error");
    //		byte[] data = dataToRead.createByteArray();
    //		String fourBytesAre = conversion.convertToReadableForm(data, i, 4);
    boolean isFirstCr = conversion.isCarriageReturn(firstByte);
    boolean isSecondLineFeed = conversion.isLineFeed(secondByte);
    boolean isThirdCr = conversion.isCarriageReturn(thirdByte);
    boolean isFourthLineField = conversion.isLineFeed(fourthByte);
    if (isFirstCr && isSecondLineFeed && isThirdCr && isFourthLineField) {
        //Found end of http headers...
        processHttpMessageAndMaybeBody(memento, dataToRead, i);
        memento.setReadingHttpMessagePointer(0);
        return true;
    }
    //mark any positions for \r\n
    if (isFirstCr && isSecondLineFeed) {
        memento.addDemarcation(i);
    }
    return false;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper)

Example 17 with DataWrapper

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

the class HttpParserImpl method createHttpChunk.

private HttpChunk createHttpChunk(MementoImpl memento, int i) {
    DataWrapper dataToRead = memento.getLeftOverData();
    //split off the header AND /r/n (ie. the +2)
    List<? extends DataWrapper> split = dataGen.split(dataToRead, i + 2);
    DataWrapper chunkMetaData = split.get(0);
    memento.setLeftOverData(split.get(1));
    List<HttpChunkExtension> extensions = new ArrayList<>();
    String chunkMetaStr = chunkMetaData.createStringFrom(0, chunkMetaData.getReadableSize(), iso8859_1);
    String hexSize = chunkMetaStr.trim();
    if (chunkMetaStr.contains(";")) {
        String[] extensionsArray = chunkMetaStr.split(";");
        hexSize = extensionsArray[0];
        for (int n = 1; n < extensionsArray.length; n++) {
            HttpChunkExtension ext = createExtension(extensionsArray[n]);
            extensions.add(ext);
        }
    }
    int chunkSize = Integer.parseInt(hexSize, 16);
    HttpChunk chunk = new HttpChunk();
    if (chunkSize == 0)
        chunk = new HttpLastChunk();
    //must read in all the data of the chunk AND /r/n
    int size = 2 + chunkSize;
    memento.setNumBytesLeftToReadOnChunk(size);
    return chunk;
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) HttpLastChunk(org.webpieces.httpparser.api.dto.HttpLastChunk) ArrayList(java.util.ArrayList) HttpChunkExtension(org.webpieces.httpparser.api.dto.HttpChunkExtension) HttpChunk(org.webpieces.httpparser.api.dto.HttpChunk)

Example 18 with DataWrapper

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

the class MockHttp1Channel method write.

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

Example 19 with DataWrapper

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

the class MockHttp2Channel method sendPrefaceAndSettings.

public void sendPrefaceAndSettings(SettingsFrame settings) {
    String preface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n";
    byte[] bytes = preface.getBytes(StandardCharsets.UTF_8);
    DataWrapper data = parser.marshal(marshalState, settings);
    DataWrapper prefaceWrapper = dataGen.wrapByteArray(bytes);
    DataWrapper all = dataGen.chainDataWrappers(prefaceWrapper, data);
    ByteBuffer buf = ByteBuffer.wrap(all.createByteArray());
    listener.incomingData(mockHttp2Channel, buf);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer)

Example 20 with DataWrapper

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

the class MockHttp2Channel method send.

public void send(Http2Msg msg) {
    if (listener == null)
        throw new IllegalStateException("Not connected so we cannot write back");
    DataWrapper data = parser.marshal(marshalState, msg);
    byte[] bytes = data.createByteArray();
    if (bytes.length == 0)
        throw new IllegalArgumentException("how do you marshal to 0 bytes...WTF");
    ByteBuffer buf = ByteBuffer.wrap(bytes);
    listener.incomingData(mockHttp2Channel, buf);
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) ByteBuffer(java.nio.ByteBuffer)

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