@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { return chain.proceed(request) .flatMap(response -> Eventual.from(processAsynchronously(response, config.delayMillis()))); }
/** * Aggregates content stream and converts this request to a {@link HttpRequest}. * <p> * Returns a {@link Eventual} that eventually produces a * {@link HttpRequest}. The resulting full request object has the same * request line, headers, and content as this request. * <p> * The content stream is aggregated asynchronously. The stream may be connected * to a network socket or some other content producer. Once aggregated, a * HttpRequest object is emitted on the returned {@link Eventual}. * <p> * A sole {@code maxContentBytes} argument is a backstop defence against excessively * long content streams. The {@code maxContentBytes} should be set to a sensible * value according to your application requirements and heap size. When the content * size stream exceeds the {@code maxContentBytes}, a @{link ContentOverflowException} * is emitted on the returned observable. * * @param maxContentBytes maximum expected content size * @return a {@link Eventual} */ public Eventual<HttpRequest> aggregate(int maxContentBytes) { return Eventual.from( body.aggregate(maxContentBytes) .thenApply(it -> new HttpRequest.Builder(this, decodeAndRelease(it)).build()) ); }
@Test public void createFromCompletionStage() { CompletableFuture<String> future = new CompletableFuture<>(); Eventual<String> eventual = Eventual.from(future); StepVerifier.create(eventual) .thenRequest(1) .expectNextCount(0) .then(() -> future.complete("hello")) .expectNext("hello") .verifyComplete(); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { return chain.proceed(request) .flatMap(response -> response.aggregate(this.maxContentLength)) .flatMap(fullResponse -> Eventual.from(asyncEvent(this.delayMillis)) .map(x -> fullResponse)) .map(HttpResponse::stream); }
/** * Aggregates content stream and converts this response to a {@link HttpResponse}. * <p> * Returns a {@link Eventual <HttpResponse>} that eventually produces a * {@link HttpResponse}. The resulting full response object has the same * response line, headers, and content as this response. * <p> * The content stream is aggregated asynchronously. The stream may be connected * to a network socket or some other content producer. Once aggregated, a * HttpResponse object is emitted on the returned {@link Eventual}. * <p> * A sole {@code maxContentBytes} argument is a backstop defence against excessively * long content streams. The {@code maxContentBytes} should be set to a sensible * value according to your application requirements and heap size. When the content * size stream exceeds the {@code maxContentBytes}, a @{link ContentOverflowException} * is emitted on the returned observable. * * @param maxContentBytes maximum expected content size * @return a {@link Eventual} */ public Eventual<HttpResponse> aggregate(int maxContentBytes) { return Eventual.from(body.aggregate(maxContentBytes)) .map(it -> new HttpResponse.Builder(this, decodeAndRelease(it)) .disableValidation() .build() ); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { return request.aggregate(config.maxContentLength()) .flatMap(fullHttpRequest -> Eventual.from(asyncOperation(config.delayMillis()))) .map(outcome -> request.newBuilder().header("X-Outcome", outcome.result())) .flatMap(x -> chain.proceed(request)); } }