File: request_body.t

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 (79 lines) | stat: -rw-r--r-- 1,400 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
76
77
78
79
use strict;
use warnings FATAL => 'all';

use Apache::Test;

use Apache::TestUtil;
use Apache::TestRequest;

plan tests => 5;

my $location = "/TestCompat__request_body";

# $r->send_http_header('text/plain');
{
    my @data = (test => 'content-type');
    ok t_cmp(
        HEAD(query(@data))->content_type(),
        "text/plain",
        q{$r->send_http_header('text/plain')}
        );
}

# $r->content
{
    my @data = (test => 'content');
    my $content = join '=', @data;
    ok t_cmp(
        POST_BODY($location, content => $content),
        "@data",
        q{$r->content via POST}
        );
}

# $r->Apache2::args
{
    my @data = (test => 'args');
    ok t_cmp(
        GET_BODY(query(@data)),
        "@data",
        q{$r->Apache2::args}
        );
}

# encoding/decoding
{
    my %data = (
        test => 'decoding',
        body => '%DC%DC+%EC%2E+%D6%D6+%D6%2F',
    );
    ok t_cmp(
        GET_BODY(query(%data)),
        $data{body},
        q{decoding}
       );
}


# big POST
{
    my %data = (
        test => 'big_input',
        body => ('x' x 819_235),
       );
    my $content = join '=', %data;
    ok t_cmp(
        POST_BODY($location, content => $content),
        length($data{body}),
        q{big POST}
       );
}



### helper subs ###
sub query {
    my (%args) = (@_ % 2) ? %{+shift} : @_;
    "$location?" . join '&', map { "$_=$args{$_}" } keys %args;
}