Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle redirects manually #363

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -150,21 +150,28 @@ private void awaitPublication(URI uri, Duration timeout) throws IOException {
var uriBuilder = URIBuilder.base(uri);
var client = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(30))
.followRedirects(HttpClient.Redirect.NORMAL)
.build();
while (Instant.now().isBefore(end)) {
var uncachedUri = uriBuilder.setQuery(Map.of("nocache", UUID.randomUUID().toString())).build();
log.fine("Validating webrev URL: " + uncachedUri);
var request = HttpRequest.newBuilder(uncachedUri)
.timeout(Duration.ofSeconds(30))
.GET()
.build();
try {
var response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() < 400) {
if (response.statusCode() < 300) {
log.info(response.statusCode() + " when checking " + uncachedUri + " - success!");
// Success!
return;
}
if (response.statusCode() < 400) {
var newLocation = response.headers().firstValue("location");
if (newLocation.isPresent()) {
log.info("Webrev url redirection: " + newLocation.get());
uriBuilder = URIBuilder.base(newLocation.get());
continue;
}
}
log.info(response.statusCode() + " when checking " + uncachedUri + " - waiting...");
Thread.sleep(Duration.ofSeconds(10).toMillis());
} catch (InterruptedException ignored) {
@@ -41,7 +41,7 @@ public void handle(HttpExchange exchange) throws IOException {
var response = "ok!";
var responseBytes = response.getBytes(StandardCharsets.UTF_8);
if (!exchange.getRequestURI().toString().contains("final=true")) {
exchange.getResponseHeaders().add("Location", exchange.getRequestURI().toString() + "&final=true");
exchange.getResponseHeaders().add("Location", uri() + "&final=true");
exchange.sendResponseHeaders(302, responseBytes.length);
} else {
redirectFollowed = true;