@Test public void returnsEarlyWhenHeaderIsPresent() { EarlyReturnExamplePlugin plugin = new EarlyReturnExamplePlugin(); LiveHttpRequest request = LiveHttpRequest.get("/") .header("X-Respond", "foo") .build(); HttpInterceptor.Chain chain = request1 -> Eventual.of(LiveHttpResponse.response().build()); Eventual<LiveHttpResponse> eventualLive = plugin.intercept(request, chain); Eventual<HttpResponse> eventual = eventualLive.flatMap(response -> response.aggregate(100)); HttpResponse response = Mono.from(eventual).block(); assertThat(response.bodyAs(UTF_8), is("Responding from plugin")); }
@Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { if (request.header("X-Respond").isPresent()) { return Eventual.of(HttpResponse.response(OK) .header(CONTENT_TYPE, "text/plain; charset=utf-8") .body("Responding from plugin", UTF_8) .build() .stream()); } else { return chain.proceed(request); } }
EarlyReturnExamplePlugin implements Plugin { @Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { if (request.header("X-Respond").isPresent()) { return Eventual.of(HttpResponse.response(OK) .header(CONTENT_TYPE, "text/plain; charset=utf-8") .body("Responding from plugin", UTF_8) .build() .stream()); } else { return chain.proceed(request); } } }
EarlyReturnExamplePlugin implements Plugin { @Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { if (request.header("X-Respond").isPresent()) { return Eventual.of(HttpResponse.response(OK) .header(CONTENT_TYPE, "text/plain; charset=utf-8") .body("Responding from plugin", UTF_8) .build() .stream()); } else { return chain.proceed(request); } }  }
EarlyReturnExamplePlugin implements Plugin { @Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { if (request.header("X-Respond").isPresent()) { return Eventual.of(HttpResponse.response(OK) .header(CONTENT_TYPE, "text/plain; charset=utf-8") .body("Responding from plugin", UTF_8) .build() .stream()); } else { return chain.proceed(request); } }  @Override Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain); }
EarlyReturnExamplePlugin implements Plugin { @Override public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) { if (request.header("X-Respond").isPresent()) { return Eventual.of(HttpResponse.response(OK) .header(CONTENT_TYPE, "text/plain; charset=utf-8") .body("Responding from plugin", UTF_8) .build() .stream()); } else { return chain.proceed(request); } }  @Override Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain);  }