diff options
Diffstat (limited to 'Bugzilla')
-rw-r--r-- | Bugzilla/CGI.pm | 11 | ||||
-rw-r--r-- | Bugzilla/Quantum/CGI.pm | 13 | ||||
-rw-r--r-- | Bugzilla/Quantum/Stdout.pm | 41 |
3 files changed, 59 insertions, 6 deletions
diff --git a/Bugzilla/CGI.pm b/Bugzilla/CGI.pm index 99957c59c..b38c248a4 100644 --- a/Bugzilla/CGI.pm +++ b/Bugzilla/CGI.pm @@ -601,11 +601,18 @@ sub header { } my $headers = $self->SUPER::header(%headers) || ''; if ($self->server_software eq 'Bugzilla::Quantum::CGI') { - my $c = $Bugzilla::C; + my $c = $Bugzilla::Quantum::CGI::C; $c->res->headers->parse($headers); - if ($c->res->headers->status =~ /^([0-9]+)/) { + my $status = $c->res->headers->status; + if ($status && $status =~ /^([0-9]+)/) { $c->res->code($1); } + elsif ($c->res->headers->location) { + $c->res->code(302); + } + else { + $c->res->code(200); + } return ''; } else { diff --git a/Bugzilla/Quantum/CGI.pm b/Bugzilla/Quantum/CGI.pm index c0fb04c22..9874280bc 100644 --- a/Bugzilla/Quantum/CGI.pm +++ b/Bugzilla/Quantum/CGI.pm @@ -21,6 +21,8 @@ use Socket qw(AF_INET inet_aton); use Sys::Hostname; use English qw(-no_match_vars); +our $C; + sub load_all { my ($class, $r) = @_; my $stash = Package::Stash->new(__PACKAGE__); @@ -61,12 +63,13 @@ sub _load_cgi { my ($c) = @_; my $stdin = $c->_STDIN; my $stdout = ''; - local %ENV = $c->_ENV; + local $C = $c; + local %ENV = $c->_ENV($file); local *STDIN; ## no critic (local) local $CGI::Compile::USE_REAL_EXIT = 0; local $PROGRAM_NAME = $file; open STDIN, '<', $stdin->path or die "STDIN @{[$stdin->path]}: $!" if -s $stdin->path; - tie STDOUT, 'Bugzilla::Quantum::Stdout', controller => $c; ## no critic (tie) + tie *STDOUT, 'Bugzilla::Quantum::Stdout', controller => $c; ## no critic (tie) try { Bugzilla->init_page(); $inner->(); @@ -75,6 +78,8 @@ sub _load_cgi { die $_ unless ref $_ eq 'ARRAY' && $_->[0] eq "EXIT\n" || /\bModPerl::Util::exit\b/; } finally { + untie *STDOUT; + $c->finish; Bugzilla->_cleanup; ## no critic (private) CGI::initialize_globals(); }; @@ -83,7 +88,7 @@ sub _load_cgi { } sub _ENV { - my ($c) = @_; + my ($c, $script_name) = @_; my $tx = $c->tx; my $req = $tx->req; my $headers = $req->headers; @@ -119,7 +124,7 @@ sub _ENV { REMOTE_PORT => $tx->remote_port, REMOTE_USER => $remote_user || '', REQUEST_METHOD => $req->method, - SCRIPT_NAME => $req->env->{SCRIPT_NAME}, + SCRIPT_NAME => "/$script_name", SERVER_NAME => hostname, SERVER_PORT => $tx->local_port, SERVER_PROTOCOL => $req->is_secure ? 'HTTPS' : 'HTTP', # TODO: Version is missing diff --git a/Bugzilla/Quantum/Stdout.pm b/Bugzilla/Quantum/Stdout.pm new file mode 100644 index 000000000..fe2d2eff7 --- /dev/null +++ b/Bugzilla/Quantum/Stdout.pm @@ -0,0 +1,41 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# +# This Source Code Form is "Incompatible With Secondary Licenses", as +# defined by the Mozilla Public License, v. 2.0. + +package Bugzilla::Quantum::Stdout; +use 5.10.1; +use Moo; + +has 'controller' => ( + is => 'ro', + required => 1, +); + +sub TIEHANDLE { ## no critic (unpack) + my $class = shift; + + return $class->new(@_); +} + +sub PRINTF { ## no critic (unpack) + my $self = shift; + $self->PRINT(sprintf @_); +} + +sub PRINT { ## no critic (unpack) + my $self = shift; + + foreach my $chunk (@_) { + utf8::encode($chunk); + $self->controller->write($chunk); + } +} + +sub BINMODE { + # no-op +} + +1;
\ No newline at end of file |