]> git.donarmstrong.com Git - debbugs.git/blob - t/17_version_cgi.t
assume unknown encodings are UTF-8
[debbugs.git] / t / 17_version_cgi.t
1 # -*- mode: cperl;-*-
2
3 use warnings;
4 use strict;
5
6 use Test::More;
7 # The test functions are placed here to make things easier
8 use lib qw(t/lib);
9 use DebbugsTest qw(:all);
10
11 plan tests => 3;
12
13 my $port = 11344;
14
15 my $version_cgi_handler = sub {
16     my $fh;
17     open($fh,'-|',-e './cgi/version.cgi'? './cgi/version.cgi' : '../cgi/version.cgi');
18     my $headers;
19     my $status = 200;
20     while (<$fh>) {
21         if (/^\s*$/ and $status) {
22             print "HTTP/1.1 $status OK\n";
23             print $headers;
24             $status = 0;
25             print $_;
26         } elsif ($status) {
27             $headers .= $_;
28             if (/^Status:\s*(\d+)/i) {
29                 $status = $1;
30             }
31         } else {
32             print $_;
33         }
34     }
35 };
36
37
38 ok(DebbugsTest::HTTPServer::fork_and_create_webserver($version_cgi_handler,$port),
39    'forked HTTP::Server::Simple successfully');
40
41 use LWP::UserAgent;
42 my $ua = LWP::UserAgent->new;
43 $ua->agent("DebbugsTesting/0.1 ");
44
45 # Create a request
46 my $req = HTTP::Request->new(GET => "http://localhost:$port/");
47
48 my $res = $ua->request($req);
49 ok($res->is_success(),'cgi/version.cgi returns success');
50 my $etag = $res->header('Etag');
51
52 $req = HTTP::Request->new(GET => "http://localhost:$port/",['If-None-Match',$etag]);
53 $res = $ua->request($req);
54 ok($res->code() eq '304','If-None-Match set gives us 304 not modified');
55
56
57