use of ratpack.http.RequestBodyAlreadyReadException in project ratpack by ratpack.
the class RequestBody method read.
@Override
public Promise<ByteBuf> read(long maxContentLength, Block onTooLarge) {
return Promise.<ByteBuf>async(downstream -> {
if (read) {
downstream.error(new RequestBodyAlreadyReadException());
return;
}
read = true;
this.onTooLarge = onTooLarge;
if (advertisedLength > maxContentLength || length > maxContentLength) {
tooLarge(downstream);
} else if (done) {
complete(downstream);
} else {
this.maxContentLength = maxContentLength;
this.downstream = downstream;
if (HttpUtil.is100ContinueExpected(request)) {
HttpResponse continueResponse = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE, Unpooled.EMPTY_BUFFER);
ctx.writeAndFlush(continueResponse).addListener(future -> {
if (!future.isSuccess()) {
ctx.fireExceptionCaught(future.cause());
}
});
}
ctx.read();
}
});
}
Aggregations