/** * Aggregates and converts this streaming request FullHttpResponse. * <p> * Aggregates up to maxContentLength bytes of HTTP response content stream. Once content is * aggregated, this streaming HttpResponse instance is converted to a FullHttpResponse object * with the aggregated content set as a message body. * <p> * This method aggregates the content stream asynchronously. Once the FullHttpResponse is * available, it will be emitted as an Observable onNext event. If the number of content bytes * exceeds maxContentLength an exception is emitted as Observable onError event. * <p> * Performance considerations: An instantiation of FullHttpResponse takes a copy of the aggregated * HTTP message content. * * @param maxContentLength Maximum content bytes accepted from the HTTP content stream. * @return An {Observable} that emits the FullHttpResponse once it is available. */ public Observable<FullHttpResponse> toFullResponse(int maxContentLength) { return body.aggregate(maxContentLength) .map(decoded -> new FullHttpResponse.Builder(this, decoded.copy().array())) .map(FullHttpResponse.Builder::build); }
public Observable<FullHttpResponse> toFullHttpResponse(int maxContentBytes) { CompositeByteBuf byteBufs = compositeBuffer(); return body .lift(disableFlowControl()) .doOnError(e -> byteBufs.release()) .collect(() -> byteBufs, (composite, part) -> { long newSize = composite.readableBytes() + part.readableBytes(); if (newSize > maxContentBytes) { release(composite); release(part); throw new ContentOverflowException(format("Maximum content size exceeded. Maximum size allowed is %d bytes.", maxContentBytes)); } composite.addComponent(part); composite.writerIndex(composite.writerIndex() + part.readableBytes()); }) .map(StreamingHttpResponse::decodeAndRelease) .map(decoded -> new FullHttpResponse.Builder(this, decoded).build()); }
public Builder newBuilder() { return new Builder(this); }
/** * Creates an HTTP response builder with a given status and empty body. * * @param status response status * @return a new builder */ public static Builder response(HttpResponseStatus status) { return new Builder(status); }
/** * Creates an HTTP response builder with a status of 200 OK and empty body. * * @return a new builder */ public static Builder response() { return new Builder(); }