Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (34 sloc) 1.06 KB
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 1.t'
#########################
use strict;
use Test::More tests => 11;
# <1>
BEGIN { use_ok('HTTP::Parser') };
#########################
my $parser = HTTP::Parser->new();
my @lines = ('GET / HTTP/1.1','Host: localhost','Connection: close','');
my @ok = (-2,-2,-2,0);
# <4>
my $result;
$parser->add("\x0a\x0a"); # blank lines before Request-Line should be ignored
for my $line(@lines) {
$result = $parser->add("$line\x0d\x0a");
is($result,shift @ok,"Passing '$line'");
}
# <6>
if($result) {
skip "Didn't get request object", 6;
} else {
my $req = $parser->request();
isa_ok($req,'HTTP::Request');
is($req->method(),'GET','Method');
my $uri = $req->uri();
isa_ok($uri,'URI');
is($uri->path(),'/','URI path');
my @head;
$req->headers->scan(sub { push @head, [@_] });
ok(eq_set(\@head,[[Connection => 'close'], [Host => 'localhost'],
['X-HTTP-Version' => '1.1']]),'Headers');
is($req->content,'','Content');
}
Something went wrong with that request. Please try again.