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;
}
}
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;
}
Aggregations