/** * Aggregates and converts this streaming request FullHttpRequest. * <p> * Aggregates up to maxContentLength bytes of HTTP request content stream. Once content is * aggregated, this streaming HttpRequest instance is converted to a FullHttpRequest object * with the aggregated content set as a message body. * <p> * This method aggregates the content stream asynchronously. Once the FullHttpRequest 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 FullHttpRequest takes a copy of the aggregated * HTTP message content. * <p> * @param maxContentLength Maximum content bytes accepted from the HTTP content stream. * @return An {Observable} that emits the FullHttpRequest once it is available. */ public <T> Observable<FullHttpRequest> toFullRequest(int maxContentLength) { return body.aggregate(maxContentLength) .map(decoded -> new FullHttpRequest.Builder(this, decoded.copy().array())) .map(FullHttpRequest.Builder::build); }
public Observable<FullHttpRequest> toFullHttpRequest(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(StreamingHttpRequest::decodeAndRelease) .map(decoded -> new FullHttpRequest.Builder(this, decoded).build()); }
/** * Return a new {@link Builder} that will inherit properties from this request. * This allows a new request to be made that will be identical to this one except for the properties * overridden by the builder methods. * * @return new builder based on this request */ public Builder newBuilder() { return new Builder(this); }
/** * Creates a request with the GET method. * * @param uri URI * @return {@code this} */ public static <T> Builder get(String uri) { return new Builder(GET, uri); }
/** * Creates a request with the POST method. * * @param uri URI * @return {@code this} */ public static <T> Builder post(String uri) { return new Builder(POST, uri); }
/** * Creates a request with the PATCH method. * * @param uri URI * @return {@code this} */ public static <T> Builder patch(String uri) { return new Builder(PATCH, uri); }
/** * Creates a request with the PUT method. * * @param uri URI * @return {@code this} */ public static <T> Builder put(String uri) { return new Builder(PUT, uri); }
/** * Creates a request with the HEAD method. * * @param uri URI * @return {@code this} */ public static <T> Builder head(String uri) { return new Builder(HEAD, uri); }
/** * Creates a request with the DELETE method. * * @param uri URI * @return {@code this} */ public static <T> Builder delete(String uri) { return new Builder(DELETE, uri); }