use server.onDispose().block() instead of Thread.sleep(Long.MAX_VALUE) (#19)

This commit is contained in:
bopol 2021-02-09 20:30:34 +01:00 committed by GitHub
parent 74d6d89b52
commit 935ec90710
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,7 @@ import me.kavin.piped.utils.ResponseHelper;
import me.kavin.piped.utils.SponsorBlockUtils; import me.kavin.piped.utils.SponsorBlockUtils;
import reactor.core.publisher.Flux; import reactor.core.publisher.Flux;
import reactor.netty.ByteBufFlux; import reactor.netty.ByteBufFlux;
import reactor.netty.DisposableServer;
import reactor.netty.NettyOutbound; import reactor.netty.NettyOutbound;
import reactor.netty.http.server.HttpServer; import reactor.netty.http.server.HttpServer;
import reactor.netty.http.server.HttpServerResponse; import reactor.netty.http.server.HttpServerResponse;
@ -32,7 +33,7 @@ public class Main {
NewPipe.init(new DownloaderImpl(), new Localization("en", "US")); NewPipe.init(new DownloaderImpl(), new Localization("en", "US"));
HttpServer.create().port(Constants.PORT).route(routes -> { DisposableServer server = HttpServer.create().port(Constants.PORT).route(routes -> {
routes.get("/webhooks/pubsub", (req, res) -> { routes.get("/webhooks/pubsub", (req, res) -> {
@ -220,9 +221,9 @@ public class Main {
}); });
}).bindNow(); }).compress(true).bindNow();
Thread.sleep(Long.MAX_VALUE); server.onDispose().block();
} }
public static NettyOutbound writeResponse(HttpServerResponse res, String resp, int code, String cache, long time) { public static NettyOutbound writeResponse(HttpServerResponse res, String resp, int code, String cache, long time) {
@ -248,7 +249,7 @@ public class Main {
} }
public static NettyOutbound writeResponse(HttpServerResponse res, byte[] resp, String mimeType, int code, String cache, long time) { public static NettyOutbound writeResponse(HttpServerResponse res, byte[] resp, String mimeType, int code, String cache, long time) {
return res.compression(true) return res
.status(code) .status(code)
.addHeader(CONTENT_TYPE, mimeType) .addHeader(CONTENT_TYPE, mimeType)
.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*") .addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
@ -268,7 +269,7 @@ public class Main {
} }
public static NettyOutbound writeResponse(HttpServerResponse res, Flux<String> resp, String mimeType, int code, String cache) { public static NettyOutbound writeResponse(HttpServerResponse res, Flux<String> resp, String mimeType, int code, String cache) {
return res.compression(true) return res
.status(code) .status(code)
.addHeader(CONTENT_TYPE, mimeType) .addHeader(CONTENT_TYPE, mimeType)
.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*") .addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, "*")