File Coverage

blib/lib/WARC/Record/Replay/HTTP/Request.pm
Criterion Covered Total %
statement 35 35 100.0
branch 6 6 100.0
condition n/a
subroutine 6 6 100.0
pod n/a
total 47 47 100.0


line stmt bran cond sub pod time code
1             package WARC::Record::Replay::HTTP::Request; # -*- CPerl -*-
2              
3 3     3   22 use strict;
  3         6  
  3         97  
4 3     3   17 use warnings;
  3         6  
  3         169  
5              
6             require HTTP::Request;
7             require WARC::Record::Replay::HTTP::Message;
8             our @ISA = qw(WARC::Record::Replay::HTTP::Message HTTP::Request);
9              
10 3     3   20 use WARC; *WARC::Record::Replay::HTTP::Request::VERSION = \$WARC::VERSION;
  3         7  
  3         504  
11              
12             require WARC::Record::Replay;
13              
14             WARC::Record::Replay::register
15             { $_->field('Content-Type') =~ m|^application/http; msgtype=request| }
16             \&_load_record;
17             WARC::Record::Replay::register
18             { $_->field('Content-Type') =~ m|^application/http| && $_->type eq 'request' }
19             \&_load_record;
20              
21             BEGIN {
22 3     3   22 use WARC::Record::Replay::HTTP;
  3         6  
  3         165  
23             $WARC::Record::Replay::HTTP::Request::{$_} =
24             $WARC::Record::Replay::HTTP::{$_}
25 3     3   828 for WARC::Record::Replay::HTTP::HTTP_PARSE_REs;
26             }
27              
28              
29             sub _load_record {
30 56     56   99 my $record = shift;
31              
32 56         140 my $handle = $record->open_continued;
33              
34 56 100       165 if ($record->field('Content-Length')
35             < $WARC::Record::Replay::HTTP::Content_Deferred_Loading_Threshold) {
36             # The entire WARC block is smaller than the deferred loading threshold;
37             # this is an easy special case.
38 44         70 my $block;
39             {
40 44         69 local $/ = undef; # slurp
  44         166  
41 44         235 $block = <$handle>;
42             }
43 44         326 my $request = HTTP::Request->parse($block);
44 44 100       19001 return $request->protocol =~ $HTTP__Version ? $request : undef;
45             }
46              
47 12         43 my $method; my $uri; my $http_version;
  12         0  
48             {
49 12         18 local $/ = "\012";
  12         50  
50 12         56 my $line = <$handle>;
51 12         102 $line =~ s/[[:space:]]+$//; # trim trailing CR if present
52 12 100       143 return undef unless $line =~ $HTTP__Request_Line;
53             # $1 -- HTTP Method $2 -- Request-URI $3 -- HTTP-Version
54 10         63 $method = $1; $uri = $2; $http_version = $3;
  10         23  
  10         38  
55             }
56              
57 10         64 my $ob = HTTP::Request->new($method, $uri);
58 10         1262 $ob->protocol($http_version);
59              
60 10         115 WARC::Record::Replay::HTTP::Message::_load_record($ob, $record, $handle);
61             }
62              
63             1;
64             __END__