From 7d8d873fc49b6a577c922358345b4e96e131b585 Mon Sep 17 00:00:00 2001 From: Lucas Gabriel Vuotto Date: Sat, 3 May 2025 17:57:42 +0000 Subject: [PATCH] site: use no_redirect for randomized endpoints As a really nice consequence, drop max_redirects from Mojo::UserAgent. --- lib/Pooru/Site.pm | 3 +-- lib/Pooru/Site/Controller/Random.pm | 11 ++++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/Pooru/Site.pm b/lib/Pooru/Site.pm index fefe051..64ec316 100644 --- a/lib/Pooru/Site.pm +++ b/lib/Pooru/Site.pm @@ -96,8 +96,7 @@ sub startup ($self) $self->ua ->connect_timeout(5) - ->inactivity_timeout(5) - ->max_redirects(1); + ->inactivity_timeout(5); my $r = $self->routes; diff --git a/lib/Pooru/Site/Controller/Random.pm b/lib/Pooru/Site/Controller/Random.pm index 74d24c3..e8e2b95 100644 --- a/lib/Pooru/Site/Controller/Random.pm +++ b/lib/Pooru/Site/Controller/Random.pm @@ -7,7 +7,8 @@ sub media ($self) { $self->render_later; - my $endpoint = $self->api_v0_url->path("random/media"); + my $endpoint = $self->api_v0_url + ->path("random/media")->query(no_redirect => 1); $self->ua->get_p($endpoint)->then(sub ($tx) { return $self->render( text => "Backend error.", @@ -15,7 +16,7 @@ sub media ($self) ) if $tx->error; return $self->redirect_to("show_media", - media_id => $tx->res->json->{id}); + media_id => $tx->res->json); })->wait; } @@ -23,16 +24,16 @@ sub tag ($self) { $self->render_later; - my $endpoint = $self->api_v0_url->path("random/tag"); + my $endpoint = $self->api_v0_url + ->path("random/tag")->query(no_redirect => 1); $self->ua->get_p($endpoint)->then(sub ($tx) { return $self->render( text => "Backend error.", status => 500, ) if $tx->error; - my %tag = $tx->res->json->%*; my $url = $self->url_for("list_media") - ->query(tags => $tag{display} . " "); + ->query(tags => $tx->res->json . " "); return $self->redirect_to($url); })->wait; }