diff options
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/Quantum.pm | 1 | ||||
-rw-r--r-- | Bugzilla/Quantum/Plugin/Hostage.pm (renamed from Bugzilla/ModPerl/Hostage.pm) | 51 |
2 files changed, 31 insertions, 21 deletions
diff --git a/Bugzilla/Quantum.pm b/Bugzilla/Quantum.pm index 9457da311..b11e183d2 100644 --- a/Bugzilla/Quantum.pm +++ b/Bugzilla/Quantum.pm @@ -31,6 +31,7 @@ sub startup { my ($self) = @_; $self->plugin('Bugzilla::Quantum::Plugin::Glue'); + $self->plugin('Bugzilla::Quantum::Plugin::Hostage'); my $r = $self->routes; Bugzilla::Quantum::CGI->load_all($r); diff --git a/Bugzilla/ModPerl/Hostage.pm b/Bugzilla/Quantum/Plugin/Hostage.pm index a3bdfac58..42a05a910 100644 --- a/Bugzilla/ModPerl/Hostage.pm +++ b/Bugzilla/Quantum/Plugin/Hostage.pm @@ -1,9 +1,6 @@ -package Bugzilla::ModPerl::Hostage; +package Bugzilla::Quantum::Plugin::Hostage; use 5.10.1; -use strict; -use warnings; - -use Apache2::Const qw(:common); ## no critic (Freenode::ModPerl) +use Mojo::Base 'Mojolicious::Plugin'; sub _attachment_root { my ($base) = @_; @@ -24,8 +21,14 @@ sub _attachment_host_regex { return qr/^$regex$/s; } -sub handler { - my $r = shift; +sub register { + my ( $self, $app, $conf ) = @_; + + $app->hook(before_routes => \&_before_routes); +} + +sub _before_routes { + my ( $c ) = @_; state $urlbase = Bugzilla->localconfig->{urlbase}; state $urlbase_uri = URI->new($urlbase); state $urlbase_host = $urlbase_uri->host; @@ -34,37 +37,43 @@ sub handler { state $attachment_root = _attachment_root($attachment_base); state $attachment_host_regex = _attachment_host_regex($attachment_base); - my $hostname = $r->hostname; - return OK if $hostname eq $urlbase_host; + my $stash = $c->stash; + my $req = $c->req; + my $url = $req->url->to_abs; + + return if $stash->{'mojo.static'}; + + my $hostname = $url->host; + return if $hostname eq $urlbase_host; - my $path = $r->uri; - return OK if $path eq '/__lbheartbeat__'; + my $path = $url->path; + return if $path eq '/__lbheartbeat__'; if ($attachment_base && $hostname eq $attachment_root) { - $r->headers_out->set(Location => $urlbase); - return REDIRECT; + $c->redirect_to($urlbase); + return; } elsif ($attachment_base && $hostname =~ $attachment_host_regex) { if ($path =~ m{^/attachment\.cgi}s) { - return OK; + return; } else { - my $new_uri = URI->new($r->unparsed_uri); + my $new_uri = $url->clone; $new_uri->scheme($urlbase_uri->scheme); $new_uri->host($urlbase_host); - $r->headers_out->set(Location => $new_uri); - return REDIRECT; + $c->redirect_to($new_uri); + return; } } elsif (my ($id) = $hostname =~ $urlbase_host_regex) { my $new_uri = $urlbase_uri->clone; $new_uri->path('/show_bug.cgi'); $new_uri->query_form(id => $id); - $r->headers_out->set(Location => $new_uri); - return REDIRECT; + $c->redirect_to($new_uri); + return; } else { - $r->headers_out->set(Location => $urlbase); - return REDIRECT; + $c->redirect_to($urlbase); + return; } } |