@Test public void testDropMessage() { ByteBuf data = ByteBufAllocator.DEFAULT.buffer(); data.writeCharSequence("test", Charset.defaultCharset()); doTestDropData( (req, res) -> res.header("Content-Length", "0") .sendObject(data), (req, out) -> out); assertThat(ReferenceCountUtil.refCnt(data)).isEqualTo(0); }
@Test public void testDropMessageConnectionClose() { ByteBuf data = ByteBufAllocator.DEFAULT.buffer(); data.writeCharSequence("test", Charset.defaultCharset()); doTestDropData( (req, res) -> res.header("Content-Length", "0") .sendObject(data), (req, out) -> { req.addHeader("Connection", "close"); return out; }); assertThat(ReferenceCountUtil.refCnt(data)).isEqualTo(0); }
private Mono<Void> ok(HttpServerResponse httpResponse, ServiceMessage response) { ByteBuf content = response.hasData(ByteBuf.class) ? response.data() : encodeData(response.data(), response.dataFormatOrDefault()); return httpResponse.status(OK).sendObject(content).then(); }
private Mono<Void> error(HttpServerResponse httpResponse, ServiceMessage response) { int code = Integer.parseInt(Qualifier.getQualifierAction(response.qualifier())); HttpResponseStatus status = HttpResponseStatus.valueOf(code); ByteBuf content = response.hasData(ErrorData.class) ? encodeData(response.data(), response.dataFormatOrDefault()) : response.data(); return httpResponse.status(status).sendObject(content).then(); }
private Mono<Void> ok(HttpServerResponse httpResponse, ServiceMessage response) { ByteBuf content = response.hasData(ByteBuf.class) ? response.data() : encodeData(response.data(), response.dataFormatOrDefault()); return httpResponse.status(OK).sendObject(content).then(); }
private Mono<Void> error(HttpServerResponse httpResponse, ServiceMessage response) { int code = response.errorType(); HttpResponseStatus status = HttpResponseStatus.valueOf(code); ByteBuf content = response.hasData(ErrorData.class) ? encodeData(response.data(), response.dataFormatOrDefault()) : response.data(); return httpResponse.status(status).sendObject(content).then(); }
@Test public void serverInfiniteClientClose() throws Exception { CountDownLatch latch = new CountDownLatch(1); DisposableServer c = HttpServer.create() .port(0) .handle((req, resp) -> { req.withConnection(cn -> cn.onDispose(latch::countDown)); return Flux.interval(Duration.ofSeconds(1)) .flatMap(d -> resp.withConnection(cn -> cn.channel() .config() .setAutoRead(true)) .sendObject(Unpooled.EMPTY_BUFFER) .then() .doOnSuccess(x -> req.withConnection( cn -> cn.channel() .config() .setAutoRead(false)))); }) .wiretap(true) .bindNow(); createHttpClientForContextWithPort(c) .get() .uri("/") .response() .block(); latch.await(); c.disposeNow(); }