private Mono<Void> handle(HttpServerRequest req, HttpServerResponse res) { res.status(HttpResponseStatus.OK); res.addHeader("Content-Type", TextFormat.CONTENT_TYPE_004); return res.sendString(Mono.just(registry.scrape())).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 sendZipFileCompressionSize_2() throws IOException { Path path = Files.createTempFile(null, ".zip"); Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING); path.toFile().deleteOnExit(); try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) { Path fromZipFile = zipFs.getPath("/largeFile.txt"); long fileSize = Files.size(fromZipFile); assertSendFile(out -> out.addHeader(HttpHeaderNames.CONTENT_LENGTH, "1245") .sendFile(fromZipFile, 0, fileSize), true, 2048, (req, res) -> true); } }
@Test public void sendZipFileCompressionSize_4() throws IOException { Path path = Files.createTempFile(null, ".zip"); Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING); path.toFile().deleteOnExit(); try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) { Path fromZipFile = zipFs.getPath("/largeFile.txt"); long fileSize = Files.size(fromZipFile); assertSendFile(out -> out.addHeader(HttpHeaderNames.CONTENT_LENGTH, "1245") .sendFile(fromZipFile, 0, fileSize), true, 512, (req, res) -> false); } }
@Test public void sendZipFileCompressionSize_3() throws IOException { Path path = Files.createTempFile(null, ".zip"); Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING); path.toFile().deleteOnExit(); try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) { Path fromZipFile = zipFs.getPath("/largeFile.txt"); long fileSize = Files.size(fromZipFile); assertSendFile(out -> out.addHeader(HttpHeaderNames.CONTENT_LENGTH, "1245") .sendFile(fromZipFile, 0, fileSize), true, 512, null); } }
@Test public void sendZipFileCompressionSize_1() throws IOException { Path path = Files.createTempFile(null, ".zip"); Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING); path.toFile().deleteOnExit(); try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) { Path fromZipFile = zipFs.getPath("/largeFile.txt"); long fileSize = Files.size(fromZipFile); assertSendFile(out -> out.addHeader(HttpHeaderNames.CONTENT_LENGTH, "1245") .sendFile(fromZipFile, 0, fileSize), true, 2048, null); } }
@Test public void sendZipFileCompressionPredicate_2() throws IOException { Path path = Files.createTempFile(null, ".zip"); Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING); path.toFile().deleteOnExit(); try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) { Path fromZipFile = zipFs.getPath("/largeFile.txt"); long fileSize = Files.size(fromZipFile); assertSendFile(out -> out.addHeader("test", "test").sendFile(fromZipFile, 0, fileSize), true, -1, (req, res) -> res.responseHeaders().contains("test")); } }
@Test public void sendZipFileCompressionPredicate_3() throws IOException { Path path = Files.createTempFile(null, ".zip"); Files.copy(this.getClass().getResourceAsStream("/zipFile.zip"), path, StandardCopyOption.REPLACE_EXISTING); path.toFile().deleteOnExit(); try (FileSystem zipFs = FileSystems.newFileSystem(path, null)) { Path fromZipFile = zipFs.getPath("/largeFile.txt"); long fileSize = Files.size(fromZipFile); assertSendFile(out -> out.addHeader("test", "test").sendFile(fromZipFile, 0, fileSize), true, -1, (req, res) -> !res.responseHeaders().contains("test")); } }
response.chunkedTransfer(false); return response.addHeader("Content-type", "text/plain") .addHeader("Expires", "0") .addHeader("X-GPFDIST-VERSION", "Spring XD") .addHeader("X-GP-PROTO", "1") .addHeader("Cache-Control", "no-cache") .addHeader("Connection", "close") .options(NettyPipeline.SendOptions::flushOnEach) .send(bufferStream.doOnNext(d -> integer.getAndIncrement())
@Test public void testDeferredHeader() { DisposableServer context = HttpServer.create() .host("localhost") .route(r -> r.get("/201", (req, res) -> res.addHeader ("Content-Length", "0") .status(HttpResponseStatus.CREATED) .sendHeaders())) .bindNow(); createHttpClientForContextWithAddress(context) .headersWhen(h -> Mono.just(h.set("test", "test")).delayElement(Duration.ofSeconds(2))) .observe((c, s) -> System.out.println(s + "" + c)) .get() .uri("/201") .responseContent() .repeat(4) .blockLast(); context.disposeNow(); }
HttpServer.create() .host("localhost") .route(r -> r.put("/201", (req, res) -> res.addHeader("Content-Length", "0") .status(HttpResponseStatus.CREATED) .sendHeaders()) .put("/204", (req, res) -> res.status(HttpResponseStatus.NO_CONTENT) .sendHeaders()) .get("/200", (req, res) -> res.addHeader("Content-Length", "0") .sendHeaders())) .bindNow();
@Test public void testCookie() { DisposableServer context = HttpServer.create() .host("localhost") .route(r -> r.get("/201", (req, res) -> res.addHeader("test", req.cookies() .get("test") .stream() .findFirst() .get() .value()) .status(HttpResponseStatus.CREATED) .sendHeaders())) .bindNow(); createHttpClientForContextWithAddress(context) .cookie("test", c -> c.setValue("lol")) .get() .uri("/201") .responseContent() .blockLast(); context.disposeNow(); }
.route(r -> r.get("/", (request, response) -> { response.addHeader("X-CUSTOM", "12345");