Write the documentation before the code for novelty value
[catagits/Catalyst-TraitFor-Request-ProxyBase.git] / lib / Catalyst / TraitFor / Request / ProxyBase.pm
1 package Catalyst::TraitFor::Request::ProxyBase;
2 use Moose::Role;
3 use namespace::autoclean;
4
5 requires 'base';
6
7 around 'base' => sub {
8     my ($orig, $self, @args) = @_;
9     my $ret = $self->$orig(@args);
10     warn blessed $ret;
11     # FIXME - Mangle here.
12     return $ret;
13 };
14
15 1;
16
17 __END__
18
19 =head1 NAME
20
21 Catalyst::TraitFor::Request::ProxyBase -
22
23 =head1 SYNOPSIS
24
25     package MyApp;
26     use Moose;
27     use namespace::autoclean;
28
29     use Catalyst;
30     use CatalystX::RoleApplicator;
31
32     extends 'Catalyst';
33
34     __PACKAGE__->apply_request_class_roles(qw/
35         Catalyst::TraitFor::Request::ProxyBase
36     /);
37
38     __PACKAGE__->config( using_frontend_proxy => 1 );
39     __PACKAGE__->setup;
40
41 =head1 DESCRIPTION
42
43 This module is a L<Moose::Role> which allows you more flexibility in your
44 application's deployment configurations when deployed behind a proxy.
45
46 The problem is that there is no standard way for a proxy to tell a backend
47 server what the original URI for the request was, or if the request was
48 initially SSL. (Yes, I do know about C<< X-Forwarded-Host >>, but they don't
49 do enough)
50
51 This creates an issue for someone wanting to deploy the same cluster of
52 application servers behind various URI endpoints.
53
54 Using this module, with the C<< using_frontend_proxy >> configuration
55 directive activates it's behavior. The request base (C<< $c->req->base >>)
56 is replaced with the contents of the C<< X-Request-Base >> header,
57 which is expected to be a full URI, for example:
58
59     http://example.com
60     https://example.com
61     http://other.example.com:81/foo/bar/yourapp
62
63 This value will then be used as the base for uris constructed by
64 C<< $c->uri_for >>.
65
66 =head1 REQUIRED METHODS
67
68 =over
69
70 =item base
71
72 =back
73
74 =head1 WRAPPED METHODS
75
76 =head2 base
77
78 FIXME
79
80 =head1 BUGS
81
82 Probably. Patches welcome, please fork from:
83
84     http://github.com/bobtfish/catalyst-traitfor-request-proxybase
85
86 and send a pull request.
87
88 =head1 AUTHOR
89
90 Tomas Doran (t0m) C<< <bobtfish@bobtfish.net> >>
91
92 =head1 COPYRIGHT
93
94 This module is Copyright (c) 2009 Tomas Doran and is licensed under the same
95 terms as perl itself.
96
97 =cut
98