From 935312b7f10857f0ece01697355ec7bf2247e461 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Tue, 11 Jan 2011 13:57:50 -0600 Subject: just save the entire original uri --- lib/Plack/Client.pm | 12 +++++------- lib/Plack/Client/Backend/psgi_local.pm | 8 ++++++-- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/Plack/Client.pm b/lib/Plack/Client.pm index a3f2211..813351c 100644 --- a/lib/Plack/Client.pm +++ b/lib/Plack/Client.pm @@ -227,8 +227,8 @@ sub _http_request_to_env { my $self = shift; my ($req) = @_; - my $scheme = $req->uri->scheme; - my $authority = $req->uri->authority; + my $scheme = $req->uri->scheme; + my $original_uri = $req->uri->clone; # hack around with this - psgi requires a host and port to exist, and # for the scheme to be either http or https @@ -253,9 +253,7 @@ sub _http_request_to_env { # work around http::message::psgi bug - see github issue 150 for plack $env->{CONTENT_LENGTH} ||= length($req->content); - $env->{'plack.client.url_scheme'} = $scheme; - $env->{'plack.client.authority'} = $authority - if defined $authority; + $env->{'plack.client.original_uri'} = $original_uri; return $env; } @@ -264,9 +262,9 @@ sub _app_from_request { my $self = shift; my ($req) = @_; - my $scheme = $req->env->{'plack.client.url_scheme'} || $req->uri->scheme; + my $uri = $req->env->{'plack.client.original_uri'} || $req->uri; - my $backend = $self->backend($scheme); + my $backend = $self->backend($uri); my $app = $backend->app_from_request($req); croak "Couldn't find app" unless $app; diff --git a/lib/Plack/Client/Backend/psgi_local.pm b/lib/Plack/Client/Backend/psgi_local.pm index 68f6eff..1da572b 100644 --- a/lib/Plack/Client/Backend/psgi_local.pm +++ b/lib/Plack/Client/Backend/psgi_local.pm @@ -78,11 +78,15 @@ sub app_from_request { my $self = shift; my ($req) = @_; - my $app_name = $req->env->{'plack.client.authority'}; - if (!defined $app_name) { + my $app_name; + if (my $uri = $req->env->{'plack.client.original_uri'}) { + $app_name = $uri->authority; + } + else { $app_name = $req->uri->authority; $app_name =~ s/(.*):.*/$1/; # in case a port was added at some point } + my $app = $self->app_for($app_name); croak "Unknown app: $app_name" unless $app; return Plack::Middleware::ContentLength->wrap($app); -- cgit v1.2.3-54-g00ecf