List of usage examples for io.netty.handler.codec.http HttpChunkedInput readChunk
@Override public HttpContent readChunk(ByteBufAllocator allocator) throws Exception
From source file:com.google.devtools.build.lib.remote.blobstore.http.HttpUploadHandlerTest.java
License:Open Source License
private void uploadsShouldWork(boolean casUpload, EmbeddedChannel ch, HttpResponseStatus status) throws Exception { ByteArrayInputStream data = new ByteArrayInputStream(new byte[] { 1, 2, 3, 4, 5 }); ChannelPromise writePromise = ch.newPromise(); ch.writeOneOutbound(new UploadCommand(CACHE_URI, casUpload, "abcdef", data, 5), writePromise); HttpRequest request = ch.readOutbound(); assertThat(request.method()).isEqualTo(HttpMethod.PUT); assertThat(request.headers().get(HttpHeaders.CONNECTION)).isEqualTo(HttpHeaderValues.KEEP_ALIVE.toString()); HttpChunkedInput content = ch.readOutbound(); assertThat(content.readChunk(ByteBufAllocator.DEFAULT).content().readableBytes()).isEqualTo(5); FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); ch.writeInbound(response);//from w w w . ja va2 s . com assertThat(writePromise.isDone()).isTrue(); assertThat(ch.isOpen()).isTrue(); }
From source file:org.robotbrains.support.web.server.netty.NettyHttpFileUpload.java
License:Apache License
/** * Add a new chunk of data to the upload. * * @param ctx/*ww w . j a v a 2 s. c om*/ * the context for the channel handling * @param chunk * the chunked data * * @throws Exception * problem adding chunk * */ public void addChunk(ChannelHandlerContext ctx, HttpChunkedInput chunk) throws Exception { decoder.offer(chunk.readChunk(ctx)); try { while (decoder.hasNext()) { InterfaceHttpData data = decoder.next(); if (data != null) { processHttpData(data); } if (chunk.isEndOfInput()) { break; } } } catch (EndOfDataDecoderException e) { getLog().error("Error while adding HTTP chunked POST data", e); } }