@Override protected Mono<Void> writeWithInternal(Publisher<? extends DataBuffer> publisher) { return this.response.send(toByteBufs(publisher)).then(); }
@Override protected Mono<Void> writeWithInternal(Publisher<? extends DataBuffer> publisher) { return this.response.send(toByteBufs(publisher)).then(); }
@Override public Mono<Void> sendNotFound() { return this.status(HttpResponseStatus.NOT_FOUND) .send(); }
@Override public Mono<Void> sendNotFound() { return this.status(HttpResponseStatus.NOT_FOUND) .send(); }
@Override protected Mono<Void> writeWithInternal(Publisher<? extends DataBuffer> publisher) { Publisher<ByteBuf> body = toByteBufs(publisher); return this.response.send(body).then(); }
private Mono<Void> noContent(HttpServerResponse httpResponse) { return httpResponse.status(NO_CONTENT).send(); }
private Mono<Void> noContent(HttpServerResponse httpResponse) { return httpResponse.status(NO_CONTENT).send(); }
@Override public Mono<Void> sendRedirect(String location) { Objects.requireNonNull(location, "location"); return this.status(HttpResponseStatus.FOUND) .header(HttpHeaderNames.LOCATION, location) .send(); }
@Override public Mono<Void> sendRedirect(String location) { Objects.requireNonNull(location, "location"); return this.status(HttpResponseStatus.FOUND) .header(HttpHeaderNames.LOCATION, location) .send(); }
@Override protected Mono<Void> writeWithInternal(Publisher<? extends DataBuffer> publisher) { return this.response.send(toByteBufs(publisher)).then(); }
private Publisher<Void> methodNotAllowed(HttpServerResponse httpResponse) { return httpResponse.addHeader(ALLOW, POST.name()).status(METHOD_NOT_ALLOWED).send(); }
private Publisher<Void> methodNotAllowed(HttpServerResponse httpResponse) { return httpResponse.addHeader(ALLOW, POST.name()).status(METHOD_NOT_ALLOWED).send(); }
@Test public void testDropPublisher() { ByteBuf data = ByteBufAllocator.DEFAULT.buffer(); data.writeCharSequence("test", Charset.defaultCharset()); doTestDropData( (req, res) -> res.header("Content-Length", "0") .send(Mono.fromRunnable(() -> Flux.just(data, data.retain(), data.retain()))) .then() .doOnCancel(() -> ReferenceCountUtil.release(data)), (req, out) -> out); assertThat(ReferenceCountUtil.refCnt(data)).isEqualTo(0); }
@Test public void testDropPublisherConnectionClose() { ByteBuf data = ByteBufAllocator.DEFAULT.buffer(); data.writeCharSequence("test", Charset.defaultCharset()); doTestDropData( (req, res) -> res.header("Content-Length", "0") .send(Mono.fromRunnable(() -> Flux.just(data, data.retain(), data.retain()))) .then() .doOnCancel(() -> ReferenceCountUtil.release(data)), (req, out) -> { req.addHeader("Connection", "close"); return out; }); assertThat(ReferenceCountUtil.refCnt(data)).isEqualTo(0); }
private Mono<Void> proxy(HttpServerRequest request, HttpServerResponse response) { return HttpClient.create() .wiretap(true) .headers(h -> h.add(filterRequestHeaders(request.requestHeaders()))) .get() .uri(URI.create("http://localhost:" + CONTENT_SERVER_PORT + "/" + request.path()) .toString()) .response((targetResponse, buf) -> response.headers(filterResponseHeaders(targetResponse.responseHeaders())) .send(buf.retain()) .then()) .then(); }
@Test(timeout = 10000) public void testHang() { DisposableServer httpServer = HttpServer.create() .port(0) .host("0.0.0.0") .route(r -> r.get("/data", (request, response) -> response.send(Mono.empty()))) .wiretap(true) .bindNow(); assertNotNull(httpServer); httpServer.disposeNow(); }
@Test @Ignore public void proxyTest() { HttpServer server = HttpServer.create(); server.route(r -> r.get("/search/{search}", (in, out) -> HttpClient.create() .wiretap(true) .get() .uri("foaas.herokuapp.com/life/" + in.param("search")) .response((repliesOut, buf) -> out.send(buf)))) .wiretap(true) .bindNow() .onDispose() .block(Duration.ofSeconds(30)); }
@Test public void clientWithoutCookieGetsANewOneFromServer() { DisposableServer server = HttpServer.create() .port(0) .route(r -> r.get("/test", (req, resp) -> resp.addCookie(new DefaultCookie("cookie1", "test_value")) .send(req.receive() .log("server received")))) .wiretap(true) .bindNow(); Mono<Map<CharSequence, Set<Cookie>>> cookieResponse = HttpClient.create() .port(server.port()) .wiretap(true) .get() .uri("/test") .responseSingle((res, buf) -> Mono.just(res.cookies())) .doOnSuccess(System.out::println) .doOnError(t -> System.err.println("Failed requesting server: " + t.getMessage())); StepVerifier.create(cookieResponse) .expectNextMatches(l -> { Set<Cookie> cookies = l.get("cookie1"); return cookies.stream().anyMatch(e -> e.value().equals("test_value")); }) .expectComplete() .verify(Duration.ofSeconds(30)); server.disposeNow(); }
@Test @Ignore public void testIssue395() throws Exception { BiFunction<HttpServerRequest, HttpServerResponse, Mono<Void>> echoHandler = (req, res) -> res.send(req.receive().map(ByteBuf::retain)).then(); SelfSignedCertificate cert = new SelfSignedCertificate(); SslContextBuilder serverOptions = SslContextBuilder.forServer(cert.certificate(), cert.privateKey()); DisposableServer server = HttpServer.create() .secure(ssl -> ssl.sslContext(serverOptions)) .protocol(HttpProtocol.H2) .handle(echoHandler) .port(8080) .wiretap(true) .bindNow(); new CountDownLatch(1).await(); server.disposeNow(); }
@Test public void testIssue186() { DisposableServer server = HttpServer.create() .port(0) .handle((req, res) -> res.status(200).send()) .wiretap(true) .bindNow(); HttpClient client = HttpClient.create(ConnectionProvider.fixed("test", 1)) .addressSupplier(server::address) .wiretap(true); try { doTestIssue186(client); doTestIssue186(client); } finally { server.disposeNow(); } }