File: rewrite.pm

package info (click to toggle)
libapache2-mod-perl2 2.0.4-7%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 9,896 kB
  • ctags: 3,820
  • sloc: perl: 56,663; ansic: 14,001; makefile: 93; sh: 38
file content (75 lines) | stat: -rw-r--r-- 1,872 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package TestUser::rewrite;

# test here the technique of rewriting the URI namespace and
# pushing/changing the query string (args). Note that in this test we
# use a custom maptostorage handler so Apache won't complain that we
# didn't set r->filename in the core maptostorage handler. the custom
# handler simply shortcuts that phase, with the added benefit of
# skipping the ap_directory_walk's stat() calls which speeds up the
# whole thing.
#
# an alternative solution is to return Apache2::Const::DECLINED from the trans
# handler, in which case map2storage is not required (but it'll do a
# bunch of stat() calls then, which you may want to avoid)

use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;

use Apache2::RequestRec ();
use Apache2::RequestIO ();
use Apache2::URI ();

use Apache2::Const -compile => qw(DECLINED OK);

my $uri_real = "/TestUser__rewrite_real";
my $args_real = "foo=bar&boo=tar";

sub trans {
    my $r = shift;

    return Apache2::Const::DECLINED unless $r->uri eq '/TestUser__rewrite';

    $r->uri($uri_real);
    $r->args($args_real);

    return Apache2::Const::OK;
}

sub map2storage {
    my $r = shift;

    return Apache2::Const::DECLINED unless $r->uri eq $uri_real;

    # skip ap_directory_walk stat() calls
    return Apache2::Const::OK;
}

sub response {
    my $r = shift;

    plan $r, tests => 1;

    my $args = $r->args();

    ok t_cmp($args, $args_real, "args");

    return Apache2::Const::OK;
}

1;
__END__
<NoAutoConfig>
  <VirtualHost TestUser::rewrite>
    PerlModule              TestUser::rewrite
    PerlTransHandler        TestUser::rewrite::trans
    PerlMapToStorageHandler TestUser::rewrite::map2storage
    <Location /TestUser__rewrite_real>
        SetHandler modperl
        PerlResponseHandler TestUser::rewrite::response
    </Location>
  </VirtualHost>
</NoAutoConfig>