X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FManual%2FRequest.pod;h=64ee38b02d5dd8a4fe9eb16ab00ba7823d1e90a2;hb=349ed61cc56d78c7ce47eb08984c65d694d3aee0;hp=f9186563e440532604a84a0e91f62806fcf95585;hpb=3fc3e4ca5cf4d934865faf8e65faa94f3b8a321e;p=maypole.git diff --git a/lib/Maypole/Manual/Request.pod b/lib/Maypole/Manual/Request.pod index f918656..64ee38b 100644 --- a/lib/Maypole/Manual/Request.pod +++ b/lib/Maypole/Manual/Request.pod @@ -1,4 +1,8 @@ -=head1 Maypole Request Hacking Cookbook +=head1 NAME + +Maypole::Manual::Request - Maypole Request Hacking Cookbook + +=head1 DESCRIPTION Hacks; design patterns; recipes: call it what you like, this chapter is a developing collection of techniques which can be slotted in to Maypole @@ -32,8 +36,8 @@ And in F, you put: It doesn't work. -B: It doesn't work because of the timing of the module -loading. C will try to set up the C relationships +B: It doesn't work because of the timing of the module loading. +C will try to set up the C relationships at compile time, when the database tables haven't even been set up, since they're set up by @@ -49,15 +53,46 @@ or move the module loading to run-time (my preferred solution): BeerDB->setup("..."); BeerDB::Beer->require; +=head3 Redirecting to SSL for sensitive information + +You have a website with forms that people will be entering sensitive information into, +such as credit cards or login details. You want to make sure that they aren't sent +in plain text but over SSL instead. + +B + +The solution is a bit tricky for 2 reasons : + +Firstly -- Many browsers and web clients will change a redirected +POST request into a GET request (which displays all that sensitive information in the +browser, or access logs and possibly elsewhere) and/or drops the values on the floor. + +Secondly -- If somebody has sent that sensitive information in plain text already, then +sending it again over SSL won't solve the problem. + +Redirecting a request is actually rather simple : + +$r->redirect_request('https://www.example.com/path'); # perldoc Maypole for API + +.. as is checking the protocol : + +$r->get_protocol(); # returns 'http' or 'https' + +You should check that the action that generates the form that people will enter +the sensitive information into is https and redirect if not. + +You should also check that no information is lost when redirecting, possibly by +storing it in a session and retrieving it later - see Maypole::Plugin::Session + =head3 Debugging with the command line You're seeing bizarre problems with Maypole output, and you want to test it in some place outside of the whole Apache/mod_perl/HTTP/Internet/browser circus. -B: Use the C module to go directly from a URL to +B: Use the L module to go directly from a URL to standard output, bypassing Apache and the network altogether. -C is not a standalone front-end, but to allow you to debug your +L is not a standalone front-end, but to allow you to debug your applications without having to change the front-end they use, it temporarily "borgs" an application. If you run it from the command line, you're expected to use it like so: @@ -72,23 +107,30 @@ You can also use the C module programatically to create test suites for your application. See the Maypole tests themselves or the documentation to C for examples of this. +Don't forget also to turn on debugging output in your application: + + package BeerDB; + use strict; + use warnings; + use Maypole::Application qw(-Debug); + =head3 Changing how URLs are parsed You don't like the way Maypole URLs look, and want something that either fits in with the rest of your site or hides the internal workings of the system. -C: So far we've been using the C form +B: So far we've been using the C form of a URL as though it was "the Maypole way"; well, there is no Maypole way. Maypole is just a framework and absolutely everything about it is overridable. If we want to provide our own URL handling, the method to override in the driver class is C. This is responsible for taking -C<$r-E{path}> and filling the C, C and C slots +C<$r-Epath> and filling the C
, C and C slots of the request object. Normally it does this just by splitting the path -on Cs, but you can do it any way you want, including getting the -information from C form parameters or session variables. +on 'C' characters, but you can do it any way you want, including +getting the information from C form parameters or session variables. For instance, suppose we want our URLs to be of the form C, we could provide a C method @@ -96,13 +138,12 @@ like so: sub parse_path { my $r = shift; - $r->{path} ||= "ProductList.html"; - ($r->{table}, $r->{action}) = - ($r->{path} =~ /^(.*?)([A-Z]\w+)\.html/); - $r->{table} = lc $r->{table}; - $r->{action} = lc $r->{action}; - my %query = $r->{ar}->args; - $self->{args} = [ $query{id} ]; + $r->path("ProductList.html") unless $r->path; + ($r->path =~ /^(.*?)([A-Z]\w+)\.html/); + $r->table(lc $1); + $r->action(lc $2); + my %query = $r->ar->args; + $self->args([ $query{id} ]); } This takes the path, which already has the query parameters stripped off @@ -110,7 +151,8 @@ and parsed, and finds the table and action portions of the filename, lower-cases them, and then grabs the C from the query. Later methods will confirm whether or not these tables and actions exist. -See L for another example of custom URL processing. +See the L for another +example of custom URL processing. =head3 Maypole for mobile devices @@ -126,7 +168,7 @@ putting this method in our driver class: sub get_template_root { my $r = shift; - my $browser = $r->{ar}->headers_in->get('User-Agent'); + my $browser = $r->headers_in->get('User-Agent'); if ($browser =~ /mobile|palm|nokia/i) { "/home/myapp/templates/mobile"; } else { @@ -140,7 +182,7 @@ idea.) =head2 Content display hacks These hacks deal primarily with the presentation of data to the user, -modifying the C template or changing the way that the results of +modifying the F template or changing the way that the results of particular actions are displayed. =head3 Null Action @@ -156,8 +198,9 @@ way. If, on the other hand, you want to display some data, and what you're essentially doing is a variant of the C action, then you need to -ensure that you have an exported action, as described in -L: +ensure that you have an exported action, as described in the +L and C"> +chapter: sub my_view :Exported { } @@ -176,17 +219,17 @@ going to C> all along. We do this by setting the objects in the C slot and changing the C