From: Tomas Doran Date: Thu, 21 May 2009 13:44:58 +0000 (+0000) Subject: Merge the branch which gives ->req->remote_user without the deprecation code which... X-Git-Tag: 5.80005~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=8026359e6ff39e39df67381dcf52a15df78804cf Merge the branch which gives ->req->remote_user without the deprecation code which is horrrible --- diff --git a/Changes b/Changes index a917b78..c2ab3a2 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ # This file documents the revision history for Perl extension Catalyst. + - Add $c->req->remote_user to disambiguate from $c->req->user (dwc) + 5.80004 2009-05-18 17:03:23 - Rename the actions attribute in Catalyt::Controller to _controller_actions to avoid name clashes with application diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index 8a8c9e8..310553b 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -2712,6 +2712,8 @@ dkubb: Dan Kubb Drew Taylor +dwc: Daniel Westermann-Clark + esskar: Sascha Kiefer fireartist: Carl Franks diff --git a/lib/Catalyst/Engine/CGI.pm b/lib/Catalyst/Engine/CGI.pm index fa2e23e..17a6e6c 100644 --- a/lib/Catalyst/Engine/CGI.pm +++ b/lib/Catalyst/Engine/CGI.pm @@ -72,7 +72,8 @@ sub prepare_connection { $request->hostname( $ENV{REMOTE_HOST} ) if exists $ENV{REMOTE_HOST}; $request->protocol( $ENV{SERVER_PROTOCOL} ); - $request->user( $ENV{REMOTE_USER} ); + $request->user( $ENV{REMOTE_USER} ); # XXX: Deprecated. See Catalyst::Request for removal information + $request->remote_user( $ENV{REMOTE_USER} ); $request->method( $ENV{REQUEST_METHOD} ); if ( $ENV{HTTPS} && uc( $ENV{HTTPS} ) eq 'ON' ) { diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index a488acd..87b2012 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -26,7 +26,7 @@ has query_parameters => (is => 'rw', default => sub { {} }); has secure => (is => 'rw', default => 0); has captures => (is => 'rw', default => sub { [] }); has uri => (is => 'rw', predicate => 'has_uri'); -has user => (is => 'rw'); +has remote_user => (is => 'rw'); has headers => ( is => 'rw', isa => 'HTTP::Headers', @@ -126,6 +126,10 @@ has hostname => ( has _path => ( is => 'rw', predicate => '_has_path', clearer => '_clear_path' ); +# XXX: Deprecated in docs ages ago (2006), deprecated with warning in 5.8000 due +# to confusion between Engines and Plugin::Authentication. Remove in 5.8100? +has user => (is => 'rw'); + sub args { shift->arguments(@_) } sub body_params { shift->body_parameters(@_) } sub input { shift->body(@_) } @@ -587,8 +591,12 @@ sub uri_with { =head2 $req->user -Returns the currently logged in user. Deprecated. The method recommended for -newer plugins is $c->user. +Returns the currently logged in user. B, do not call, +this will be removed in version 5.81. + +=head2 $req->remote_user + +Returns the value of the C environment variable. =head2 $req->user_agent diff --git a/t/aggregate/live_engine_request_remote_user.t b/t/aggregate/live_engine_request_remote_user.t new file mode 100644 index 0000000..10b071b --- /dev/null +++ b/t/aggregate/live_engine_request_remote_user.t @@ -0,0 +1,42 @@ +#!perl + +# This tests to make sure the REMOTE_USER environment variable is properly passed through by the engine. + +use strict; +use warnings; + +use FindBin; +use lib "$FindBin::Bin/../lib"; + +use Test::More tests => 7; +use Catalyst::Test 'TestApp'; + +use Catalyst::Request; +use HTTP::Request::Common; + +{ + my $creq; + + local $ENV{REMOTE_USER} = 'dwc'; + my $request = GET( + 'http://localhost/dump/request', + ); + + ok( my $response = request($request), 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + like( $response->content, qr/'Catalyst::Request'/, + 'Content is a serialized Catalyst::Request' ); + + { + no strict 'refs'; + ok( + eval '$creq = ' . $response->content, + 'Unserialize Catalyst::Request' + ); + } + + isa_ok( $creq, 'Catalyst::Request' ); + + is( $creq->remote_user, 'dwc', '$c->req->remote_user ok' ); +} diff --git a/t/lib/DeprecatedTestApp/C/Root.pm b/t/lib/DeprecatedTestApp/C/Root.pm index 7b8b74f..9a3e1d0 100644 --- a/t/lib/DeprecatedTestApp/C/Root.pm +++ b/t/lib/DeprecatedTestApp/C/Root.pm @@ -10,4 +10,9 @@ sub index : Private { $c->res->body('root index'); } +sub req_user : Local { + my ( $self, $c ) = @_; + $c->res->body('REMOTE_USER = ' . $c->req->user); +} + 1;