fix4
This commit is contained in:
parent
4ea3d96496
commit
de7d38c596
@ -248,7 +248,9 @@ public final class XtreamPlayerApplication {
|
||||
List<URI> attempts = candidateUris(target);
|
||||
HttpResponse<byte[]> response = null;
|
||||
URI usedTarget = target;
|
||||
List<String> attemptErrors = new ArrayList<>();
|
||||
for (URI candidate : attempts) {
|
||||
try {
|
||||
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(candidate)
|
||||
.GET()
|
||||
.timeout(Duration.ofSeconds(60))
|
||||
@ -271,14 +273,22 @@ public final class XtreamPlayerApplication {
|
||||
}
|
||||
HttpRequest request = requestBuilder.build();
|
||||
HttpResponse<byte[]> candidateResponse = HTTP_CLIENT.send(request, HttpResponse.BodyHandlers.ofByteArray());
|
||||
if (response == null || response.statusCode() >= 400) {
|
||||
response = candidateResponse;
|
||||
usedTarget = candidate;
|
||||
}
|
||||
if (candidateResponse.statusCode() < 400) {
|
||||
response = candidateResponse;
|
||||
usedTarget = candidate;
|
||||
break;
|
||||
}
|
||||
} catch (Exception candidateException) {
|
||||
attemptErrors.add(maskUri(candidate) + " -> " + compactError(candidateException));
|
||||
LOGGER.warn("Stream proxy candidate failed uri={}", maskUri(candidate), candidateException);
|
||||
}
|
||||
}
|
||||
if (response == null) {
|
||||
writeJson(exchange, 502, errorJson("Unable to proxy stream: empty upstream response."));
|
||||
writeJson(exchange, 502, errorJson("Unable to proxy stream. Attempts: " + String.join(" | ", attemptErrors)));
|
||||
return;
|
||||
}
|
||||
String contentType = response.headers().firstValue("Content-Type").orElse("application/octet-stream");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user