add status code to server response

This commit is contained in:
bopol 2021-02-05 18:53:05 +01:00
parent e8c7b44e8e
commit 554d39807b

View file

@ -227,13 +227,19 @@ public class Main {
} }
public static NettyOutbound writeResponse(HttpServerResponse res, byte[] resp, int code, String cache, long time) { public static NettyOutbound writeResponse(HttpServerResponse res, byte[] resp, int code, String cache, long time) {
return res.compression(true).addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*").addHeader(CACHE_CONTROL, cache) return res.compression(true)
.status(code)
.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
.addHeader(CACHE_CONTROL, cache)
.addHeader("Server-Timing", "app;dur=" + (System.nanoTime() - time) / 1000000.0) .addHeader("Server-Timing", "app;dur=" + (System.nanoTime() - time) / 1000000.0)
.sendByteArray(Flux.just(resp)); .sendByteArray(Flux.just(resp));
} }
public static NettyOutbound writeResponse(HttpServerResponse res, Flux<String> resp, int code, String cache) { public static NettyOutbound writeResponse(HttpServerResponse res, Flux<String> resp, int code, String cache) {
return res.compression(true).addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*").addHeader(CACHE_CONTROL, cache) return res.compression(true)
.status(code)
.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
.addHeader(CACHE_CONTROL, cache)
.send(ByteBufFlux.fromString(resp, java.nio.charset.StandardCharsets.UTF_8, ByteBufAllocator.DEFAULT)); .send(ByteBufFlux.fromString(resp, java.nio.charset.StandardCharsets.UTF_8, ByteBufAllocator.DEFAULT));
} }
} }