From e216176239965bb5bd98a0008fd8c71b14ee9624 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Mon, 21 May 2018 20:54:58 -0400 Subject: almost everything works --- Bugzilla/Quantum/CGI.pm | 13 +++++++++---- Bugzilla/Quantum/Stdout.pm | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 Bugzilla/Quantum/Stdout.pm (limited to 'Bugzilla/Quantum') 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 -- cgit v1.2.3-24-g4f1b