File: 07forking.t

package info (click to toggle)
libhttp-request-ascgi-perl 0.5-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 92 kB
  • ctags: 10
  • sloc: perl: 430; makefile: 46
file content (59 lines) | stat: -rw-r--r-- 1,303 bytes parent folder | download | duplicates (7)
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
#!perl

use strict;
use warnings;

use Config;
use IO::File;
use HTTP::Request;
use HTTP::Request::AsCGI;
use Test::More;

unless ( $Config{d_fork} ) {
    plan skip_all => 'This test requires a plattform that supports fork()';
}

plan tests => 8;

my $response;

{
    my $r = HTTP::Request->new( GET => 'http://www.host.com/' );
    my $c = HTTP::Request::AsCGI->new($r);

    my $kid = fork();

    unless ( defined $kid ) {
        die("Can't fork() kid: $!");
    }

    unless ( $kid ) {

        $c->setup;

        print "HTTP/1.0 200 OK\n";
        print "Content-Type: text/plain\n";
        print "Status: 200\n";
        print "X-Field: 1\n";
        print "X-Field: 2\n";
        print "\n";
        print "Hello!";

        $c->restore;

        exit(0);
    }

    waitpid( $kid, 0 );

    $response = $c->response;
}

isa_ok( $response, 'HTTP::Response' );
is( $response->code, 200, 'Response Code' );
is( $response->message, 'OK', 'Response Message' );
is( $response->protocol, 'HTTP/1.0', 'Response Protocol' );
is( $response->content, 'Hello!', 'Response Content' );
is( $response->content_length, 6, 'Response Content-Length' );
is( $response->content_type, 'text/plain', 'Response Content-Type' );
is_deeply( [ $response->header('X-Field') ], [ 1, 2 ], 'Response Header X-Field' );