aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRblSb <msrblsb@gmail.com>2026-01-17 14:53:51 +0300
committerRblSb <msrblsb@gmail.com>2026-01-17 14:53:51 +0300
commit276e12db29ab31aa002f55b1a3cc69f170c1a2c2 (patch)
tree9b383753217abed057ab2f60ff09c977c7436ab4 /src
parentc1d1be00c7cace0544c3c6cd152e8c3287b976c4 (diff)
[proxy] fix stalled requests on seeking
and minor cache fix
Diffstat (limited to 'src')
-rw-r--r--src/server/HttpServer.hx32
-rw-r--r--src/server/cache/YoutubeCache.hx3
2 files changed, 29 insertions, 6 deletions
diff --git a/src/server/HttpServer.hx b/src/server/HttpServer.hx
index b339059..f7c6d8c 100644
--- a/src/server/HttpServer.hx
+++ b/src/server/HttpServer.hx
@@ -409,17 +409,21 @@ class HttpServer {
function proxyUrl(req:IncomingMessage, res:ServerResponse):Bool {
final url = req.url.replace("/proxy?url=", "");
final proxy = proxyRequest(url, req, res, proxyRes -> {
- final url = proxyRes.headers["location"] ?? return false;
- final proxy2 = proxyRequest(url, req, res, proxyRes -> false);
+ final redirectUrl = proxyRes.headers["location"] ?? return false;
+ final proxy2 = proxyRequest(redirectUrl, req, res, proxyRes -> false);
if (proxy2 == null) {
- res.end('Proxy error: multiple redirects for url $url');
+ if (!res.headersSent) {
+ res.end('Proxy error: multiple redirects for url $redirectUrl');
+ }
return true;
}
req.pipe(proxy2);
+ req.on("error", () -> proxy2.destroy());
return true;
});
if (proxy == null) return false;
req.pipe(proxy);
+ req.on("error", () -> proxy.destroy());
return true;
}
@@ -443,16 +447,34 @@ class HttpServer {
};
req.headers["referer"] = url.toString();
req.headers["host"] = url.hostname;
+
final request = url.protocol == "https:" ? Https.request : Http.request;
final proxy = request(options, proxyRes -> {
- if (cancelProxyRequest(proxyRes)) return;
+ if (cancelProxyRequest(proxyRes)) {
+ proxyRes.destroy();
+ return;
+ }
proxyRes.headers["content-type"] = "application/octet-stream";
res.writeHead(proxyRes.statusCode, proxyRes.headers);
proxyRes.pipe(res);
+
+ // clean up when response ends
+ proxyRes.on("end", () -> {
+ if (!res.writableEnded) res.end();
+ });
});
+
proxy.on("error", err -> {
- res.end('Proxy error: ${url.href}');
+ proxy.destroy();
+ if (!res.headersSent) {
+ res.end('Proxy error: ${url.href}');
+ }
});
+ // clean up when client disconnects (seeking/abort)
+ res.on("close", () -> {
+ if (!proxy.destroyed) proxy.destroy();
+ });
+
return proxy;
}
diff --git a/src/server/cache/YoutubeCache.hx b/src/server/cache/YoutubeCache.hx
index 0618d00..158cfe1 100644
--- a/src/server/cache/YoutubeCache.hx
+++ b/src/server/cache/YoutubeCache.hx
@@ -198,9 +198,10 @@ class YoutubeCache {
});
dlVideo.then((v) -> {
- final name = cache.findFile(n -> n.startsWith(inVideoName) && n.endsWith(".mp4")) ?? {
+ final name = cache.findFile(n -> n.startsWith(inVideoName)) ?? {
final err = 'Error: cannot find downloaded file with prefix $inVideoName';
cache.logWithAdmins(client, err);
+ cancelProgress(clientName);
return;
};
FileSystem.rename('${cache.cacheDir}/$name', '${cache.cacheDir}/$outName');
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage