use of io.netty.handler.codec.http.DefaultHttpContent in project riposte by Nike-Inc.
the class RequestInfoImplTest method addContentChunk_does_not_add_chunk_to_contentChunks_list_if_contentChunksWillBeReleasedExternally_is_true.
@Test
public void addContentChunk_does_not_add_chunk_to_contentChunks_list_if_contentChunksWillBeReleasedExternally_is_true() {
// given
RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
requestInfo.isCompleteRequestWithAllChunks = false;
requestInfo.contentChunksWillBeReleasedExternally();
HttpContent chunk = new DefaultHttpContent(Unpooled.copiedBuffer(UUID.randomUUID().toString(), CharsetUtil.UTF_8));
// when
requestInfo.addContentChunk(chunk);
// then
Assertions.assertThat(requestInfo.contentChunks).isEmpty();
}
use of io.netty.handler.codec.http.DefaultHttpContent in project riposte by Nike-Inc.
the class HttpUtilsTest method convertContentChunksToRawString_and_convertContentChunksToRawBytes_works.
@Test
@DataProvider(value = { "somecontent1234!@#$%^&*/?.,<>;:'\"{}[]() | alsosomecontent1234!@#$%^&*/?.,<>;:'\"{}[]() | UTF-8", "somecontent1234!@#$%^&*/?.,<>;:'\"{}[]() | alsosomecontent1234!@#$%^&*/?.,<>;:'\"{}[]() | UTF-16", "somecontent1234!@#$%^&*/?.,<>;:'\"{}[]() | alsosomecontent1234!@#$%^&*/?.,<>;:'\"{}[]() | ISO-8859-1" }, splitBy = "\\|")
public void convertContentChunksToRawString_and_convertContentChunksToRawBytes_works(String chunk1Base, String chunk2Base, String charsetString) throws IOException {
// given
Charset contentCharset = Charset.forName(charsetString);
String chunk1Content = chunk1Base + "-" + UUID.randomUUID().toString();
String chunk2Content = chunk2Base + "-" + UUID.randomUUID().toString();
byte[] chunk1Bytes = chunk1Content.getBytes(contentCharset);
byte[] chunk2Bytes = chunk2Content.getBytes(contentCharset);
ByteBuf chunk1ByteBuf = Unpooled.copiedBuffer(chunk1Bytes);
ByteBuf chunk2ByteBuf = Unpooled.copiedBuffer(chunk2Bytes);
Collection<HttpContent> chunkCollection = Arrays.asList(new DefaultHttpContent(chunk1ByteBuf), new DefaultHttpContent(chunk2ByteBuf));
// when
String resultString = HttpUtils.convertContentChunksToRawString(contentCharset, chunkCollection);
byte[] resultBytes = HttpUtils.convertContentChunksToRawBytes(chunkCollection);
// then
String expectedResultString = chunk1Content + chunk2Content;
assertThat(resultString, is(expectedResultString));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(chunk1Bytes);
baos.write(chunk2Bytes);
assertThat(resultBytes, is(baos.toByteArray()));
}
use of io.netty.handler.codec.http.DefaultHttpContent in project riposte by Nike-Inc.
the class RequestInfoImplTest method addContentChunk_adds_chunk_content_length_to_rawContentLengthInBytes.
@Test
public void addContentChunk_adds_chunk_content_length_to_rawContentLengthInBytes() throws IOException {
// given
RequestInfoImpl<?> requestInfo = RequestInfoImpl.dummyInstanceForUnknownRequests();
requestInfo.isCompleteRequestWithAllChunks = false;
String chunk1String = UUID.randomUUID().toString();
String lastChunkString = UUID.randomUUID().toString();
byte[] chunk1Bytes = chunk1String.getBytes();
byte[] lastChunkBytes = lastChunkString.getBytes();
HttpContent chunk1 = new DefaultHttpContent(Unpooled.copiedBuffer(chunk1Bytes));
HttpContent lastChunk = new DefaultLastHttpContent(Unpooled.copiedBuffer(lastChunkBytes));
// when
requestInfo.addContentChunk(chunk1);
requestInfo.addContentChunk(lastChunk);
// then
assertThat(requestInfo.contentChunks.size(), is(2));
assertThat(requestInfo.isCompleteRequestWithAllChunks(), is(true));
assertThat(requestInfo.getRawContentLengthInBytes(), is(chunk1Bytes.length + lastChunkBytes.length));
}
use of io.netty.handler.codec.http.DefaultHttpContent in project asterixdb by apache.
the class ChunkedNettyOutputStream method flush.
private void flush(byte[] buf, int offset, int len) throws IOException {
ensureWritable();
ByteBuf aBuffer = ctx.alloc().buffer(len);
aBuffer.writeBytes(buf, offset, len);
if (response.status() == HttpResponseStatus.OK) {
response.beforeFlush();
ctx.write(new DefaultHttpContent(aBuffer), ctx.channel().voidPromise());
} else {
response.error(aBuffer);
}
}
Aggregations