diff options
author | Jesse Luehrs <doy@tozt.net> | 2011-01-07 16:43:29 -0600 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2011-01-07 16:47:45 -0600 |
commit | 459dd0062bfc3ff82ee10a01e7dbb34ae003ce21 (patch) | |
tree | d997873c67e1c0c4ec001904e4ea18727951ba7c /lib/Plack/Client/Backend/psgi_local.pm | |
parent | 6cf2b2c70509a7a0c92239af5d0978140f9ec674 (diff) | |
download | plack-client-459dd0062bfc3ff82ee10a01e7dbb34ae003ce21.tar.gz plack-client-459dd0062bfc3ff82ee10a01e7dbb34ae003ce21.zip |
factor out scheme handling into separate backends
docs still need updating
Diffstat (limited to 'lib/Plack/Client/Backend/psgi_local.pm')
-rw-r--r-- | lib/Plack/Client/Backend/psgi_local.pm | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/Plack/Client/Backend/psgi_local.pm b/lib/Plack/Client/Backend/psgi_local.pm new file mode 100644 index 0000000..212479e --- /dev/null +++ b/lib/Plack/Client/Backend/psgi_local.pm @@ -0,0 +1,41 @@ +package Plack::Client::Backend::psgi_local; +use strict; +use warnings; + +use Plack::Middleware::ContentLength; + +sub new { + my $class = shift; + my %params = @_; + + die 'apps must be a hashref' + if exists($params{apps}) && ref($params{apps}) ne 'HASH'; + + bless { + apps => $params{apps}, + }, $class; +} + +sub apps { shift->{apps} } + +sub app_for { + my $self = shift; + my ($for) = @_; + return $self->apps->{$for}; +} + +sub app_from_req { + my $self = shift; + my ($req) = @_; + + my $app_name = $req->env->{'plack.client.authority'}; + if (!defined $app_name) { + $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); + die "Unknown app: $app_name" unless $app; + return Plack::Middleware::ContentLength->wrap($app); +} + +1; |