summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-01-11 13:57:50 -0600
committerJesse Luehrs <doy@tozt.net>2011-01-11 14:02:47 -0600
commit935312b7f10857f0ece01697355ec7bf2247e461 (patch)
tree8c8848f165d4fa5dd9d3171b3a634cf371fd43c2
parent811c7f969dba4962943550c0b74e5ad179860683 (diff)
downloadplack-client-935312b7f10857f0ece01697355ec7bf2247e461.tar.gz
plack-client-935312b7f10857f0ece01697355ec7bf2247e461.zip
just save the entire original uri
-rw-r--r--lib/Plack/Client.pm12
-rw-r--r--lib/Plack/Client/Backend/psgi_local.pm8
-rw-r--r--t/02-inputs.t8
-rw-r--r--t/03-delayed-response.t8
-rw-r--r--t/04-streaming.t8
5 files changed, 17 insertions, 27 deletions
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);
diff --git a/t/02-inputs.t b/t/02-inputs.t
index 3b7260a..094aec6 100644
--- a/t/02-inputs.t
+++ b/t/02-inputs.t
@@ -135,9 +135,7 @@ sub test_responses {
$uri->path('/') unless $uri->path; # XXX: work around plack bug
my $env = HTTP::Request->new(GET => $uri)->to_psgi;
$env->{CONTENT_LENGTH} = 0; # XXX: work around plack bug
- $env->{'plack.client.url_scheme'} = $base->scheme;
- $env->{'plack.client.app_name'} = $base->authority
- if $base->scheme eq 'psgi-local';
+ $env->{'plack.client.original_uri'} = $base;
response_is(
$client->request($env),
200,
@@ -153,9 +151,7 @@ sub test_responses {
$uri->path('/') unless $uri->path; # XXX: work around plack bug
my $env = HTTP::Request->new(GET => $uri)->to_psgi;
$env->{CONTENT_LENGTH} = 0; # XXX: work around plack bug
- $env->{'plack.client.url_scheme'} = $base->scheme;
- $env->{'plack.client.app_name'} = $base->authority
- if $base->scheme eq 'psgi-local';
+ $env->{'plack.client.original_uri'} = $base;
response_is(
$client->request(Plack::Request->new($env)),
200,
diff --git a/t/03-delayed-response.t b/t/03-delayed-response.t
index ed3fbd9..d86116d 100644
--- a/t/03-delayed-response.t
+++ b/t/03-delayed-response.t
@@ -138,9 +138,7 @@ sub test_responses {
$uri->path('/') unless $uri->path; # XXX: work around plack bug
my $env = HTTP::Request->new(GET => $uri)->to_psgi;
$env->{CONTENT_LENGTH} = 0; # XXX: work around plack bug
- $env->{'plack.client.url_scheme'} = $base->scheme;
- $env->{'plack.client.app_name'} = $base->authority
- if $base->scheme eq 'psgi-local';
+ $env->{'plack.client.original_uri'} = $base;
response_is(
$client->request($env),
200,
@@ -156,9 +154,7 @@ sub test_responses {
$uri->path('/') unless $uri->path; # XXX: work around plack bug
my $env = HTTP::Request->new(GET => $uri)->to_psgi;
$env->{CONTENT_LENGTH} = 0; # XXX: work around plack bug
- $env->{'plack.client.url_scheme'} = $base->scheme;
- $env->{'plack.client.app_name'} = $base->authority
- if $base->scheme eq 'psgi-local';
+ $env->{'plack.client.original_uri'} = $base;
response_is(
$client->request(Plack::Request->new($env)),
200,
diff --git a/t/04-streaming.t b/t/04-streaming.t
index 9aaec17..6c475ff 100644
--- a/t/04-streaming.t
+++ b/t/04-streaming.t
@@ -139,9 +139,7 @@ sub test_responses {
$uri->path('/') unless $uri->path; # XXX: work around plack bug
my $env = HTTP::Request->new(GET => $uri)->to_psgi;
$env->{CONTENT_LENGTH} = 0; # XXX: work around plack bug
- $env->{'plack.client.url_scheme'} = $base->scheme;
- $env->{'plack.client.app_name'} = $base->authority
- if $base->scheme eq 'psgi-local';
+ $env->{'plack.client.original_uri'} = $base;
response_is(
$client->request($env),
200,
@@ -157,9 +155,7 @@ sub test_responses {
$uri->path('/') unless $uri->path; # XXX: work around plack bug
my $env = HTTP::Request->new(GET => $uri)->to_psgi;
$env->{CONTENT_LENGTH} = 0; # XXX: work around plack bug
- $env->{'plack.client.url_scheme'} = $base->scheme;
- $env->{'plack.client.app_name'} = $base->authority
- if $base->scheme eq 'psgi-local';
+ $env->{'plack.client.original_uri'} = $base;
response_is(
$client->request(Plack::Request->new($env)),
200,