Skip to content

Commit

Permalink
Added ->env method to Catalyst::Request, and then set PSGI env to tha…
Browse files Browse the repository at this point in the history
…t so plugins/components can use. Better done with Traits etc. i guess
  • Loading branch information
miyagawa committed Dec 18, 2009
1 parent a13d9c5 commit 01ee281
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/Catalyst/Engine/PSGI.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ our $VERSION = '0.07';
use Moose;
extends 'Catalyst::Engine';

{
# Temporary hack to see if there are better ways like TraitFor,
# but without requiring downstream changes.
sub Catalyst::Request::env {
my $req = shift;
$req->{_psgi_env} = shift if @_;
$req->{_psgi_env};
}
}

use Scalar::Util qw(blessed);
use URI;
use Catalyst::Controller::Metal;
Expand All @@ -22,10 +32,11 @@ sub _uri_safe_unescape {
sub prepare_connection {
my ( $self, $c ) = @_;

my $env = $self->env;
my $request = $c->request;
$request->address( $self->env->{REMOTE_ADDR} );
my $env = $self->env;

$request->env($env);
$request->address( $env->{REMOTE_ADDR} );
$request->hostname( $env->{REMOTE_HOST} ) if exists $env->{REMOTE_HOST};
$request->protocol( $env->{SERVER_PROTOCOL} );
$request->user( $env->{REMOTE_USER} ); # XXX: Deprecated. See Catalyst::Request for removal information
Expand All @@ -38,7 +49,7 @@ sub prepare_connection {
sub prepare_headers {
my ( $self, $c ) = @_;

my $env = $self->env;
my $env = $c->request->env;
my $headers = $c->request->headers;
foreach my $header ( keys %$env ) {
next unless $header =~ /^(HTTP|CONTENT|COOKIE)/i;
Expand All @@ -51,7 +62,7 @@ sub prepare_headers {
sub prepare_path {
my ( $self, $c ) = @_;

my $env = $self->env;
my $env = $c->request->env;

my $scheme = $c->request->secure ? 'https' : 'http';
my $host = $env->{HTTP_HOST} || $env->{SERVER_NAME};
Expand Down Expand Up @@ -96,8 +107,8 @@ around prepare_query_parameters => sub {
my $orig = shift;
my ( $self, $c ) = @_;

if ( $self->env->{QUERY_STRING} ) {
$self->$orig( $c, $self->env->{QUERY_STRING} );
if ( my $qs = $c->request->env->{QUERY_STRING} ) {
$self->$orig( $c, $qs );
}
};

Expand Down

0 comments on commit 01ee281

Please sign in to comment.