http://www.modperlcookbook.org/~geoff/
1
All Your URI are Belong to Us
Geoffrey Young
geoff@modperlcookbook.org
All Your URI are Belong to Us Geoffrey Young - - PowerPoint PPT Presentation
All Your URI are Belong to Us Geoffrey Young geoff@modperlcookbook.org 1 http://www.modperlcookbook.org/~geoff/ Apache Request Cycle Client Request Logging URI-based Init Content URI Translation Fixups File-Based Init Resource Control
http://www.modperlcookbook.org/~geoff/
1
Geoffrey Young
geoff@modperlcookbook.org
http://www.modperlcookbook.org/~geoff/
2
Client Request URI-based Init URI Translation File-Based Init Fixups Content Logging Resource Control Mime Setting
http://www.modperlcookbook.org/~geoff/
3
Client Request URI-based Init URI Translation Client Request URI-based Init
http://www.modperlcookbook.org/~geoff/
4
http://www.modperlcookbook.org/~geoff/
5
DocumentRoot /usr/local/apache/htdocs Alias /manual/ /usr/local/apache/manual/ <Directory /usr/local/apache/manual> ... </Directory>
<Location server-status> ... </Location>
http://www.modperlcookbook.org/~geoff/
6
Client Request URI-based Init PerlTransHandler Client Request URI-based Init
http://www.modperlcookbook.org/~geoff/
7
http://www.modperlcookbook.org/~geoff/
8
http://www.modperlcookbook.org/~geoff/
9
package Cookbook::Favicon; use Apache::Constants qw(DECLINED); use strict; sub handler { my $r = shift; $r->uri("/images/favicon.ico") if $r->uri =~ m!/favicon\.ico$!; return DECLINED; } 1;
http://www.modperlcookbook.org/~geoff/
10
Client Request
GET /foo/bar/baz/biff/favicon.ico HTTP/1.1 Host: www.example.com
http://www.modperlcookbook.org/~geoff/
11
Client Request URI-based Init Client Request URI-based Init
URI: /foo/bar/baz/biff/favicon.ico
PerlTransHandler
http://www.modperlcookbook.org/~geoff/
12
Client Request URI-based Init PerlTransHandler Client Request URI-based Init core translation
FILE: /usr/local/apache/htdocs/images/favicon.ico
http://www.modperlcookbook.org/~geoff/
13
http://www.modperlcookbook.org/~geoff/
14
http://www.modperlcookbook.org/~geoff/
15
RewriteRule /favicon.ico$ /images/favicon.ico
http://www.modperlcookbook.org/~geoff/
16
http://www.modperlcookbook.org/~geoff/
17
package Cookbook::URISessionManager; use Apache::Constants qw(DECLINED OK); use Apache::URI; sub get_session { my $r = shift; my $uri = $r->parsed_uri; # Separate the MD5 session from the real path. my ($session, $path) = $uri->path =~ m!^/([a-fA-F0-9]{32})(/.*)!; return DECLINED unless $session; # Now, put the session in a note... $r->notes(SESSION => $session); # ... and set the URI to the proper path. $r->uri($path); return DECLINED; } 1;
http://www.modperlcookbook.org/~geoff/
18
http://www.modperlcookbook.org/~geoff/
19
http://www.modperlcookbook.org/~geoff/
20
package Cookbook::URISessionManager; sub get_session { ... } sub clean_uri { my $r = shift; my ($uri) = $r->uri =~ m!.*(http://.*)!; $r->send_http_header('text/html'); print<<EOF; <html> <head> <meta http-equiv="refresh" content="0;URL=$uri"> </head> <body> you should be going <a href="$uri">here</a> soon </body> </html> EOF return OK; } 1;
http://www.modperlcookbook.org/~geoff/
21
PerlModule Cookbook::URISessionManager PerlTransHandler Cookbook::URISessionManager::get_session <Location /goodbye> SetHandler perl-script PerlHandler Cookbook::URISessionManager::clean_uri </Location>
http://www.modperlcookbook.org/~geoff/
22
http://www.modperlcookbook.org/~geoff/
23
http://www.modperlcookbook.org/~geoff/
24
http://www.modperlcookbook.org/~geoff/
25
http://www.modperlcookbook.org/~geoff/
26
package My::ManualProxy; use Apache::Constants qw(OK DECLINED); use strict; sub handler { my $r = shift; return DECLINED unless $r->proxyreq; my (undef, $file) = $r->uri =~ m!^http://(www|httpd).apache.org/(.*)!; if ($file =~ m!^docs/!) { $file =~ s!^docs/!manual/!; $file = join "/", ($r->document_root, $file); if (-f $file) { $r->filename($file); # use local disk return OK; } } return DECLINED; } 1;
http://www.modperlcookbook.org/~geoff/
27
Client Request URI-based Init URI Translation File-Based Init Fixups Content Logging Mime Setting Resource Control