use of org.webpieces.httpparser.api.dto.HttpChunkExtension 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;
}
use of org.webpieces.httpparser.api.dto.HttpChunkExtension in project webpieces by deanhiller.
the class TestChunkedParsing method testMarshalOut.
@Test
public void testMarshalOut() {
DataWrapper payload1 = dataGen.wrapByteArray("0123456789".getBytes());
HttpChunk chunk = new HttpChunk();
chunk.addExtension(new HttpChunkExtension("asdf", "value"));
chunk.addExtension(new HttpChunkExtension("something"));
chunk.setBody(payload1);
byte[] payload = unwrap(parser.marshalToByteBuffer(state, chunk));
String str = new String(payload);
Assert.assertEquals("a;asdf=value;something\r\n0123456789\r\n", str);
HttpLastChunk lastChunk = new HttpLastChunk();
lastChunk.addExtension(new HttpChunkExtension("this", "that"));
lastChunk.addHeader(new Header("customer", "value"));
String lastPayload = parser.marshalToString(lastChunk);
Assert.assertEquals("0;this=that\r\ncustomer: value\r\n\r\n", lastPayload);
byte[] lastBytes = unwrap(parser.marshalToByteBuffer(state, lastChunk));
String lastPayloadFromBytes = new String(lastBytes, HttpParserFactory.iso8859_1);
Assert.assertEquals("0;this=that\r\ncustomer: value\r\n\r\n", lastPayloadFromBytes);
}
Aggregations