[Rt-commit] rt branch, 4.4/migrate-cgi-env, repushed
? sunnavy
sunnavy at bestpractical.com
Fri Jan 9 09:26:42 EST 2015
The branch 4.4/migrate-cgi-env was deleted and repushed:
was aaa16b8503e2803b99332279aef9ff056a061362
now b90608fa1a12582afc9303135628d47fc84ac594
1: ece2945 ! 1: a12a694 abstract usage of cgi env variables
@@ -16,7 +16,7 @@
sub WebCanonicalizeInfo {
- return $ENV{'REMOTE_USER'} ? lc $ENV{'REMOTE_USER'} : $ENV{'REMOTE_USER'};
-+ return ENV('REMOTE_USER') ? lc ENV('REMOTE_USER') : ENV('REMOTE_USER');
++ return RequestENV('REMOTE_USER') ? lc RequestENV('REMOTE_USER') : RequestENV('REMOTE_USER');
}
@@ -26,8 +26,8 @@
# it an absolute URL.
- if ($ENV{'REQUEST_URI'}) {
- $req_uri = $ENV{'REQUEST_URI'};
-+ if (ENV('REQUEST_URI')) {
-+ $req_uri = ENV('REQUEST_URI');
++ if (RequestENV('REQUEST_URI')) {
++ $req_uri = RequestENV('REQUEST_URI');
# collapse multiple leading slashes so the first part doesn't look like
# a hostname of a schema-less URI
@@ -35,7 +35,7 @@
my $m = $HTML::Mason::Commands::m;
-+ my $remote_addr = ENV('REMOTE_ADDR');
++ my $remote_addr = RequestENV('REMOTE_ADDR');
unless ( $user_obj->id && $user_obj->IsPassword( $ARGS->{pass} ) ) {
- $RT::Logger->error("FAILED LOGIN for @{[$ARGS->{user}]} from $ENV{'REMOTE_ADDR'}");
+ $RT::Logger->error("FAILED LOGIN for @{[$ARGS->{user}]} from $remote_addr");
@@ -53,7 +53,7 @@
sub _SessionCookieName {
my $cookiename = "RT_SID_" . RT->Config->Get('rtname');
- $cookiename .= "." . $ENV{'SERVER_PORT'} if $ENV{'SERVER_PORT'};
-+ $cookiename .= "." . ENV('SERVER_PORT') if ENV('SERVER_PORT');
++ $cookiename .= "." . RequestENV('SERVER_PORT') if RequestENV('SERVER_PORT');
return $cookiename;
}
@@ -62,7 +62,7 @@
my $uri = URI->new( RT->Config->Get('WebURL') );
- if ( defined $ENV{HTTPS} and $ENV{'HTTPS'} eq 'on' ) {
-+ if ( defined ENV('HTTPS') and ENV('HTTPS') eq 'on' ) {
++ if ( defined RequestENV('HTTPS') and RequestENV('HTTPS') eq 'on' ) {
$uri->scheme('https');
}
else {
@@ -72,8 +72,8 @@
# [rt3.fsck.com #12716] Apache recommends use of $SERVER_HOST
- $uri->host( $ENV{'SERVER_HOST'} || $ENV{'HTTP_HOST'} || $ENV{'SERVER_NAME'} );
- $uri->port( $ENV{'SERVER_PORT'} );
-+ $uri->host( ENV('SERVER_HOST') || ENV('HTTP_HOST') || ENV('SERVER_NAME') );
-+ $uri->port( ENV('SERVER_PORT') );
++ $uri->host( RequestENV('SERVER_HOST') || RequestENV('HTTP_HOST') || RequestENV('SERVER_NAME') );
++ $uri->port( RequestENV('SERVER_PORT') );
return "$uri"; # stringify to be consistent with WebURL in config
}
@@ -82,7 +82,7 @@
-if (($ENV{'HTTP_USER_AGENT'} || '') =~ /(?:hiptop|Blazer|Novarra|Vagabond|SonyEricsson|Symbian|NetFront|UP.Browser|UP.Link|Windows CE|MIDP|J2ME|DoCoMo|J-PHONE|PalmOS|PalmSource|iPhone|iPod|AvantGo|Nokia|Android|WebOS|S60|Mobile)/io && !$HTML::Mason::Commands::session{'NotMobile'}) {
-+if ((ENV('HTTP_USER_AGENT') || '') =~ /(?:hiptop|Blazer|Novarra|Vagabond|SonyEricsson|Symbian|NetFront|UP.Browser|UP.Link|Windows CE|MIDP|J2ME|DoCoMo|J-PHONE|PalmOS|PalmSource|iPhone|iPod|AvantGo|Nokia|Android|WebOS|S60|Mobile)/io && !$HTML::Mason::Commands::session{'NotMobile'}) {
++if ((RequestENV('HTTP_USER_AGENT') || '') =~ /(?:hiptop|Blazer|Novarra|Vagabond|SonyEricsson|Symbian|NetFront|UP.Browser|UP.Link|Windows CE|MIDP|J2ME|DoCoMo|J-PHONE|PalmOS|PalmSource|iPhone|iPod|AvantGo|Nokia|Android|WebOS|S60|Mobile)/io && !$HTML::Mason::Commands::session{'NotMobile'}) {
return 1;
} else {
return undef;
@@ -93,13 +93,13 @@
- my $port = $ENV{SERVER_PORT};
- my $host = $ENV{HTTP_X_FORWARDED_HOST} || $ENV{HTTP_X_FORWARDED_SERVER}
- || $ENV{HTTP_HOST} || $ENV{SERVER_NAME};
-+ my $port = ENV('SERVER_PORT');
-+ my $host = ENV('HTTP_X_FORWARDED_HOST') || ENV('HTTP_X_FORWARDED_SERVER')
-+ || ENV('HTTP_HOST') || ENV('SERVER_NAME');
++ my $port = RequestENV('SERVER_PORT');
++ my $host = RequestENV('HTTP_X_FORWARDED_HOST') || RequestENV('HTTP_X_FORWARDED_SERVER')
++ || RequestENV('HTTP_HOST') || RequestENV('SERVER_NAME');
($host, $port) = ($1, $2) if $host =~ /^(.*?):(\d+)$/;
- if ( $port != RT->Config->Get('WebPort') and not $ENV{'rt.explicit_port'}) {
-+ if ( $port != RT->Config->Get('WebPort') and not ENV('rt.explicit_port')) {
++ if ( $port != RT->Config->Get('WebPort') and not RequestENV('rt.explicit_port')) {
$RT::Logger->warn("The requested port ($port) does NOT match the configured WebPort ($RT::WebPort). "
."Perhaps you should Set(\$WebPort, $port); in RT_SiteConfig.pm, "
."otherwise your internal links may be broken.");
@@ -111,10 +111,10 @@
- if ($ENV{SCRIPT_NAME} ne RT->Config->Get('WebPath') and not $proxied) {
- $RT::Logger->warn("The requested path ($ENV{SCRIPT_NAME}) does NOT match the configured WebPath ($RT::WebPath). "
- ."Perhaps you should Set(\$WebPath, '$ENV{SCRIPT_NAME}'); in RT_SiteConfig.pm, "
-+ my $proxied = ENV('HTTP_X_FORWARDED_HOST') || ENV('HTTP_X_FORWARDED_SERVER');
-+ if (ENV('SCRIPT_NAME') ne RT->Config->Get('WebPath') and not $proxied) {
-+ $RT::Logger->warn("The requested path ('" . ENV('SCRIPT_NAME') . "') does NOT match the configured WebPath ($RT::WebPath). "
-+ ."Perhaps you should Set(\$WebPath, '" . ENV('SCRIPT_NAME') . "' in RT_SiteConfig.pm, "
++ my $proxied = RequestENV('HTTP_X_FORWARDED_HOST') || RequestENV('HTTP_X_FORWARDED_SERVER');
++ if (RequestENV('SCRIPT_NAME') ne RT->Config->Get('WebPath') and not $proxied) {
++ $RT::Logger->warn("The requested path ('" . RequestENV('SCRIPT_NAME') . "') does NOT match the configured WebPath ($RT::WebPath). "
++ ."Perhaps you should Set(\$WebPath, '" . RequestENV('SCRIPT_NAME') . "' in RT_SiteConfig.pm, "
."otherwise your internal links may be broken.");
}
}
@@ -123,10 +123,10 @@
return (1,
"your browser did not supply a Referrer header", # loc
- ) if !$ENV{HTTP_REFERER};
-+ ) if !ENV('HTTP_REFERER');
++ ) if !RequestENV('HTTP_REFERER');
- my ($whitelisted, $browser, $configs) = IsRefererCSRFWhitelisted($ENV{HTTP_REFERER});
-+ my ($whitelisted, $browser, $configs) = IsRefererCSRFWhitelisted(ENV('HTTP_REFERER'));
++ my ($whitelisted, $browser, $configs) = IsRefererCSRFWhitelisted(RequestENV('HTTP_REFERER'));
return 0 if $whitelisted;
if ( @$configs > 1 ) {
@@ -134,7 +134,7 @@
return $prefix;
}
-+sub ENV {
++sub RequestENV {
+ my $name = shift;
+ return $name ? $ENV{$name} : \%ENV;
+}
@@ -147,7 +147,7 @@
);
- return unless $ENV{REQUEST_METHOD} eq 'GET';
-+ return unless ENV('REQUEST_METHOD') eq 'GET';
++ return unless RT::Interface::Web::RequestENV('REQUEST_METHOD') eq 'GET';
my $id = $args{ARGSRef}->{id};
2: 22990c9 ! 2: ce3073a use psgi env directly
@@ -2,22 +2,37 @@
use psgi env directly
- sadly we still need to keep several env vars:
+ sadly we still need to keep the following env vars:
* PATH
- with mod_fastcgi(at least), we need this to find commands like "dot"
-
- * REQUEST_METHOD and HTTP_ACCEPT_LANGUAGE
-
- they are used in I18N::LangTags::Detect(which is also called by Locale::Maketext)
+ mod_fastcgi starts with an empty %ENV, we need to update PATH to reflect the
+ value set in Apache so we can find local installed commands like "dot".
* QUERY_STRING
HTML::Mason::Utils::cgi_request_args uses it to determine if to call
- url_param or not for a weird case(see inline comments there)
+ url_param or not for a weird case(see inline comments there).
+ (t/web/dashboards-in-menu.t fails without this because we make POST requests
+ to urls with query string like /Admin/Users/DashboardsInMenu.html?id=12)
- Fixes: #30427
+ Fixes: I#30427
+
+diff --git a/lib/RT/CurrentUser.pm b/lib/RT/CurrentUser.pm
+--- a/lib/RT/CurrentUser.pm
++++ b/lib/RT/CurrentUser.pm
+@@
+ elsif ( $self->id && ($self->id == (RT->SystemUser->id||0) || $self->id == (RT->Nobody->id||0)) ) {
+ # don't use ENV magic for system users
+ push @_, 'en';
++ } elsif ($HTML::Mason::Commands::m) {
++ # Detect from the HTTP header.
++ push @_, I18N::LangTags::Detect->http_accept_langs(
++ RT::Interface::Web::RequestENV('HTTP_ACCEPT_LANGUAGE')
++ );
+ }
+
+ $self->{'LangHandle'} = RT::I18N->get_handle(@_);
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
--- a/lib/RT/Interface/Web.pm
@@ -27,7 +42,7 @@
sub LoadSessionFromCookie {
- my %cookies = CGI::Cookie->fetch;
-+ my %cookies = CGI::Cookie->parse(ENV('HTTP_COOKIE'));
++ my %cookies = CGI::Cookie->parse(RequestENV('HTTP_COOKIE'));
my $cookiename = _SessionCookieName();
my $SessionCookie = ( $cookies{$cookiename} ? $cookies{$cookiename}->value : undef );
tie %HTML::Mason::Commands::session, 'RT::Interface::Web::Session', $SessionCookie;
@@ -35,19 +50,19 @@
my $uri = URI->new( RT->Config->Get('WebURL') );
-- if ( defined ENV('HTTPS') and ENV('HTTPS') eq 'on' ) {
+- if ( defined RequestENV('HTTPS') and RequestENV('HTTPS') eq 'on' ) {
- $uri->scheme('https');
- }
- else {
- $uri->scheme('http');
- }
-+ $uri->scheme(ENV('psgi.url_scheme') || 'http');
++ $uri->scheme(RequestENV('psgi.url_scheme') || 'http');
# [rt3.fsck.com #12716] Apache recommends use of $SERVER_HOST
- $uri->host( ENV('SERVER_HOST') || ENV('HTTP_HOST') || ENV('SERVER_NAME') );
+ $uri->host( RequestENV('SERVER_HOST') || RequestENV('HTTP_HOST') || RequestENV('SERVER_NAME') );
@@
- sub ENV {
+ sub RequestENV {
my $name = shift;
- return $name ? $ENV{$name} : \%ENV;
+ my $env = $HTML::Mason::Commands::m->cgi_object->env;
@@ -67,6 +82,11 @@
+ # request. Pick it up and cache it during the first request.
+ $ENV{PATH} //= $env->{PATH};
+
++ # HTML::Mason::Utils::cgi_request_args uses $ENV{QUERY_STRING} to
++ # determine if to call url_param or not
++ # (see comments in HTML::Mason::Utils::cgi_request_args)
++ $ENV{QUERY_STRING} = $env->{QUERY_STRING};
++
{
my $res = $self->CheckModPerlHandler($env);
return $self->_psgi_response_cb( $res->finalize ) if $res;
@@ -77,7 +97,6 @@
- # XXX: until we get rid of all $ENV stuff.
- local %ENV = (%ENV, CGI::Emulate::PSGI->emulate_environment($env));
-
-+ local %ENV = (%ENV, map { $_ => $env->{$_} } grep { exists $env->{$_} } qw/HTTP_ACCEPT_LANGUAGE REQUEST_METHOD QUERY_STRING/);
$ret = $h->handle_psgi($env);
}
@@ -86,7 +105,6 @@
$ret = sub {
my $respond = shift;
- local %ENV = (%ENV, CGI::Emulate::PSGI->emulate_environment($env));
-+ local %ENV = (%ENV, map { $_ => $env->{$_} } grep { exists $env->{$_} } qw/HTTP_ACCEPT_LANGUAGE REQUEST_METHOD QUERY_STRING/);
$orig_ret->($respond);
};
}
3: aaa16b8 = 3: b90608f update the mock of $m to reflect the cgi env migration
More information about the rt-commit
mailing list