fix2
This commit is contained in:
parent
2dc782bebe
commit
43c46e266d
@ -225,6 +225,7 @@ public final class XtreamPlayerApplication {
|
||||
}
|
||||
|
||||
String rawUrl = query.getOrDefault("url", "").trim();
|
||||
String sourceUrl = query.getOrDefault("src", "").trim();
|
||||
if (rawUrl.isBlank()) {
|
||||
writeJson(exchange, 400, errorJson("Missing url parameter."));
|
||||
return;
|
||||
@ -257,6 +258,13 @@ public final class XtreamPlayerApplication {
|
||||
));
|
||||
copyRequestHeaderIfPresent(exchange, requestBuilder, "Range");
|
||||
copyRequestHeaderIfPresent(exchange, requestBuilder, "If-Range");
|
||||
if (!sourceUrl.isBlank()) {
|
||||
requestBuilder.header("Referer", sourceUrl);
|
||||
String origin = originFromUrl(sourceUrl);
|
||||
if (!origin.isBlank()) {
|
||||
requestBuilder.header("Origin", origin);
|
||||
}
|
||||
}
|
||||
HttpRequest request = requestBuilder.build();
|
||||
HttpResponse<byte[]> response = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
||||
String contentType = response.headers().firstValue("Content-Type").orElse("application/octet-stream");
|
||||
@ -756,7 +764,7 @@ public final class XtreamPlayerApplication {
|
||||
continue;
|
||||
}
|
||||
URI absolute = baseUri.resolve(trimmed);
|
||||
out.append(proxyStreamUrl(absolute.toString())).append('\n');
|
||||
out.append(proxyStreamUrl(absolute.toString(), baseUri.toString())).append('\n');
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
@ -766,15 +774,27 @@ public final class XtreamPlayerApplication {
|
||||
StringBuilder out = new StringBuilder(line.length() + 64);
|
||||
while (matcher.find()) {
|
||||
String current = matcher.group(1);
|
||||
String rewritten = proxyStreamUrl(baseUri.resolve(current).toString());
|
||||
String rewritten = proxyStreamUrl(baseUri.resolve(current).toString(), baseUri.toString());
|
||||
matcher.appendReplacement(out, "URI=\"" + Matcher.quoteReplacement(rewritten) + "\"");
|
||||
}
|
||||
matcher.appendTail(out);
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private static String proxyStreamUrl(String absoluteUrl) {
|
||||
return "/api/stream-proxy?url=" + urlEncode(absoluteUrl);
|
||||
private static String proxyStreamUrl(String absoluteUrl, String sourceUrl) {
|
||||
return "/api/stream-proxy?url=" + urlEncode(absoluteUrl) + "&src=" + urlEncode(sourceUrl);
|
||||
}
|
||||
|
||||
private static String originFromUrl(String url) {
|
||||
try {
|
||||
URI uri = URI.create(url);
|
||||
if (uri.getScheme() == null || uri.getRawAuthority() == null) {
|
||||
return "";
|
||||
}
|
||||
return uri.getScheme() + "://" + uri.getRawAuthority();
|
||||
} catch (Exception exception) {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyRequestHeaderIfPresent(HttpExchange exchange, HttpRequest.Builder requestBuilder, String headerName) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user