Search in sources :

Example 1 with HttpMessage

use of org.webpieces.httpparser.api.dto.HttpMessage in project webpieces by deanhiller.

the class HttpParserImpl method processHttpMessageAndMaybeBody.

private void processHttpMessageAndMaybeBody(MementoImpl memento, DataWrapper dataToRead, int i) {
    List<Integer> markedPositions = memento.getLeftOverMarkedPositions();
    memento.setLeftOverMarkedPositions(new ArrayList<Integer>());
    List<? extends DataWrapper> tuple = dataGen.split(dataToRead, i + 4);
    DataWrapper toBeParsed = tuple.get(0);
    memento.setLeftOverData(tuple.get(1));
    HttpMessage message = parseHttpMessage(memento, toBeParsed, markedPositions);
    if (memento.isHttp2()) {
        //memento.addMessage(message);
        return;
    }
    Header contentLenHeader = message.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
    Header transferHeader = message.getHeaderLookupStruct().getLastInstanceOfHeader(KnownHeaderName.TRANSFER_ENCODING);
    if (transferHeader != null && "chunked".equals(transferHeader.getValue())) {
        memento.setInChunkParsingMode(true);
        processChunks(memento);
        return;
    } else if (contentLenHeader != null && !"0".equals(contentLenHeader.getValue())) {
        String value = contentLenHeader.getValue();
        int length = toInteger(value, "" + contentLenHeader);
        memento.setContentLengthLeftToRead(length);
        readInContentLengthBody(memento);
        return;
    }
}
Also used : DataWrapper(org.webpieces.data.api.DataWrapper) Header(org.webpieces.httpparser.api.common.Header) HttpMessage(org.webpieces.httpparser.api.dto.HttpMessage)

Example 2 with HttpMessage

use of org.webpieces.httpparser.api.dto.HttpMessage in project webpieces by deanhiller.

the class HttpParserImpl method marshalToBytes.

public byte[] marshalToBytes(MarshalState s, HttpPayload payload) {
    MarshalStateImpl state = (MarshalStateImpl) s;
    if (state.getParsingDataSize() != null) {
        return parseData(state, payload);
    } else if (payload.getMessageType() == HttpMessageType.CHUNK || payload.getMessageType() == HttpMessageType.LAST_CHUNK) {
        return chunkedBytes((HttpChunk) payload);
    }
    HttpMessage msg = (HttpMessage) payload;
    String result = marshalHeaders(payload);
    Header header = msg.getHeaderLookupStruct().getHeader(KnownHeaderName.CONTENT_LENGTH);
    if (header != null && !header.getValue().equals("0")) {
        String value = header.getValue();
        int lengthOfBodyFromHeader = toInteger(value, "" + header);
        state.setParsingDataSize(lengthOfBodyFromHeader);
    }
    byte[] stringPiece = result.getBytes(iso8859_1);
    return stringPiece;
}
Also used : Header(org.webpieces.httpparser.api.common.Header) HttpMessage(org.webpieces.httpparser.api.dto.HttpMessage) HttpChunk(org.webpieces.httpparser.api.dto.HttpChunk)

Aggregations

Header (org.webpieces.httpparser.api.common.Header)2 HttpMessage (org.webpieces.httpparser.api.dto.HttpMessage)2 DataWrapper (org.webpieces.data.api.DataWrapper)1 HttpChunk (org.webpieces.httpparser.api.dto.HttpChunk)1