AbsoluteRedirectsMiddleware extends AbstractWebMiddleware<HttpRequest, NRES> { @Override public HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> chain) { HttpResponse response = castToHttpResponse(chain.next(request)); if (isRedirectResponse(response)) { updateHeader(response, "location", request); } return response; }  @Override HttpResponse handle(HttpRequest request, MiddlewareChain<HttpRequest, NRES, ?, ?> chain);  }
@Test void documentRootPath() { MiddlewareChain<HttpRequest, HttpResponse, ?, ?> chain = new DefaultMiddlewareChain<>(new AnyPredicate<>(), null, (Endpoint<HttpRequest, HttpResponse>) req -> builder(HttpResponse.of("hello")) .set(HttpResponse::setStatus, 303) .set(HttpResponse::setHeaders, Headers.of("Location", "/foo/bar")) .build()); HttpResponse response = middleware.handle(request, chain); assertThat(response.getHeaders().get("Location")) .isEqualTo("http: }
@Test void relativePath() { MiddlewareChain<HttpRequest, HttpResponse, ?, ?> chain = new DefaultMiddlewareChain<>(new AnyPredicate<>(), null, (Endpoint<HttpRequest, HttpResponse>) req -> builder(HttpResponse.of("hello")) .set(HttpResponse::setStatus, 303) .set(HttpResponse::setHeaders, Headers.of("Location", "foo/bar")) .build()); HttpResponse response = middleware.handle(request, chain); assertThat(response.getHeaders().get("Location")) .isEqualTo("http: }