1 package Catalyst::TraitFor::Request::ProxyBase;
4 use namespace::autoclean;
6 our $VERSION = '0.000003';
13 around 'base' => sub {
14 my ($orig, $self, @args) = @_;
15 if (my $base = $self->header('X-Request-Base')) {
16 $base .= '/' unless $base =~ m|/$|;
17 @args = (URI->new($base));
22 around 'secure' => sub {
23 my ($orig, $self, @args) = @_;
24 if (my $base = $self->header('X-Request-Base')) {
25 return URI->new($base)->scheme eq 'http' ? 0 : 1;
36 Catalyst::TraitFor::Request::ProxyBase - Replace request base with value passed by HTTP proxy
42 use namespace::autoclean;
45 use CatalystX::RoleApplicator;
49 __PACKAGE__->apply_request_class_roles(qw/
50 Catalyst::TraitFor::Request::ProxyBase
57 This module is a L<Moose::Role> which allows you more flexibility in your
58 application's deployment configurations when deployed behind a proxy.
60 The problem is that there is no standard way for a proxy to tell a backend
61 server what the original URI for the request was, or if the request was
62 initially SSL. (Yes, I do know about C<< X-Forwarded-Host >>, but they don't
65 This creates an issue for someone wanting to deploy the same cluster of
66 application servers behind various URI endpoints.
68 Using this module, the request base (C<< $c->req->base >>)
69 is replaced with the contents of the C<< X-Request-Base >> header,
70 which is expected to be a full URI, for example:
74 http://other.example.com:81/foo/bar/yourapp
76 This value will then be used as the base for uris constructed by
79 =head1 REQUIRED METHODS
89 =head1 WRAPPED METHODS
101 Probably. Patches welcome, please fork from:
103 http://github.com/bobtfish/catalyst-traitfor-request-proxybase
105 and send a pull request.
109 Tomas Doran (t0m) C<< <bobtfish@bobtfish.net> >>
113 This module is Copyright (c) 2009 Tomas Doran and is licensed under the same
114 terms as perl itself.