File: http-post.t

package info (click to toggle)
libapache-mod-perl 1.16-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,580 kB
  • ctags: 1,064
  • sloc: ansic: 4,489; perl: 4,415; sh: 305; makefile: 137
file content (58 lines) | stat: -rwxr-xr-x 1,317 bytes parent folder | download | duplicates (5)
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
#!/usr/local/bin/perl -w
#
# Check POST via HTTP.
#

use Config;

my $num_tests = 5;
my(@test_scripts) = qw(test);

#if($Config{usesfio} eq "true" or $] >= 5.003_93) {
if($] >= 5.003_93) {
    $num_tests += 2;
    push @test_scripts, qw(io/perlio.pl);
}

print "1..$num_tests\n";

use Apache::test;
require LWP::UserAgent;

my $ua = new LWP::UserAgent;    # create a useragent to test

my($request,$response,$str,$form);

foreach $script (@test_scripts) {
    $netloc = $net::httpserver;
    $script = $PERL_DIR . "/$script";

    $ua = new LWP::UserAgent;    # create a useragent to test

    $url = new URI::URL("http://$netloc$script");

    $form = 'searchtype=Substring';

    $request = new HTTP::Request('POST', $url, undef, $form);
    $request->header('Content-Type', 'application/x-www-form-urlencoded');

    $response = $ua->request($request, undef, undef);

    $str = $response->as_string;
    print "$str\n";

    die "$1\n" if $str =~ /(Internal Server Error)/;

    test ++$i, ($response->is_success and $str =~ /^REQUEST_METHOD=POST$/m);
    test ++$i, ($str =~ /^CONTENT_LENGTH=(\d+)$/m && $1 == length($form));
}

print "pounding a bit...\n";
for (1..3) {
    test ++$i, ($ua->request($request, undef, undef)->is_success);
}


# avoid -w warning
$dummy = $net::httpserver;
$dummy = $net::perldir;