line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WARC::Record::Replay::HTTP::Response; # -*- CPerl -*- |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
21
|
use strict; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
92
|
|
4
|
3
|
|
|
3
|
|
26
|
use warnings; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
163
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require HTTP::Response; |
7
|
|
|
|
|
|
|
require WARC::Record::Replay::HTTP::Message; |
8
|
|
|
|
|
|
|
our @ISA = qw(WARC::Record::Replay::HTTP::Message HTTP::Response); |
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
18
|
use WARC; *WARC::Record::Replay::HTTP::Response::VERSION = \$WARC::VERSION; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
493
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
require WARC::Record::Replay; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
WARC::Record::Replay::register |
15
|
|
|
|
|
|
|
{ $_->field('Content-Type') =~ m|^application/http; msgtype=response| } |
16
|
|
|
|
|
|
|
\&_load_record; |
17
|
|
|
|
|
|
|
WARC::Record::Replay::register |
18
|
|
|
|
|
|
|
{ $_->field('Content-Type') =~ m|^application/http| && $_->type eq 'response' } |
19
|
|
|
|
|
|
|
\&_load_record; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
BEGIN { |
22
|
3
|
|
|
3
|
|
23
|
use WARC::Record::Replay::HTTP; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
157
|
|
23
|
|
|
|
|
|
|
$WARC::Record::Replay::HTTP::Response::{$_} = |
24
|
|
|
|
|
|
|
$WARC::Record::Replay::HTTP::{$_} |
25
|
3
|
|
|
3
|
|
1561
|
for WARC::Record::Replay::HTTP::HTTP_PARSE_REs; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _load_record { |
29
|
64
|
|
|
64
|
|
121
|
my $record = shift; |
30
|
|
|
|
|
|
|
|
31
|
64
|
|
|
|
|
155
|
my $handle = $record->open_continued; |
32
|
64
|
|
|
|
|
120
|
my $ob; |
33
|
|
|
|
|
|
|
|
34
|
64
|
100
|
|
|
|
192
|
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
|
51
|
|
|
|
|
92
|
my $block; |
39
|
|
|
|
|
|
|
{ |
40
|
51
|
|
|
|
|
75
|
local $/ = undef; # slurp |
|
51
|
|
|
|
|
200
|
|
41
|
51
|
|
|
|
|
239
|
$block = <$handle>; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
# Work around a bug in LWP that can append a trailing CR to the status |
44
|
|
|
|
|
|
|
# message in an HTTP response parsed from a string. |
45
|
|
|
|
|
|
|
# |
46
|
|
|
|
|
|
|
# The response status message can contain spaces and LWP uses the |
47
|
|
|
|
|
|
|
# LIMIT parameter to split to collect all text after the status code. |
48
|
|
|
|
|
|
|
# This causes the parsed message to include the trailing CR. |
49
|
|
|
|
|
|
|
# |
50
|
|
|
|
|
|
|
# This problem does not occur with requests; the protocol version in a |
51
|
|
|
|
|
|
|
# request cannot contain spaces, so the trailing CR is counted as |
52
|
|
|
|
|
|
|
# whitespace and removed as the delimiter for a trailing empty field. |
53
|
51
|
|
|
|
|
376
|
my $response = HTTP::Response->parse($block); |
54
|
51
|
|
|
|
|
12828
|
{ my $m; |
|
51
|
|
|
|
|
86
|
|
55
|
51
|
50
|
|
|
|
119
|
if (($m = $response->message) =~ s/\015\z//) { $response->message($m) } } |
|
0
|
|
|
|
|
0
|
|
56
|
51
|
100
|
|
|
|
601
|
if ($response->protocol =~ $HTTP__Version) |
57
|
47
|
|
|
|
|
751
|
{ $ob = $response; close $handle; $handle = undef } |
|
47
|
|
|
|
|
233
|
|
|
47
|
|
|
|
|
308
|
|
58
|
|
|
|
|
|
|
else |
59
|
4
|
|
|
|
|
133
|
{ return undef } |
60
|
|
|
|
|
|
|
} else { |
61
|
13
|
|
|
|
|
33
|
my $code; my $reason; my $http_version; |
|
13
|
|
|
|
|
0
|
|
62
|
|
|
|
|
|
|
{ |
63
|
13
|
|
|
|
|
22
|
local $/ = "\012"; |
|
13
|
|
|
|
|
54
|
|
64
|
13
|
|
|
|
|
58
|
my $line = <$handle>; |
65
|
13
|
|
|
|
|
101
|
$line =~ s/[[:space:]]+$//; # trim trailing CR if present |
66
|
13
|
100
|
|
|
|
144
|
return undef unless $line =~ $HTTP__Status_Line; |
67
|
|
|
|
|
|
|
# $1 -- HTTP-Version $2 -- Status-Code $3 -- Reason-Phrase |
68
|
11
|
|
|
|
|
34
|
$http_version = $1; $code = $2; $reason = $3; |
|
11
|
|
|
|
|
24
|
|
|
11
|
|
|
|
|
40
|
|
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
11
|
|
|
|
|
72
|
$ob = HTTP::Response->new($code, $reason); |
72
|
11
|
|
|
|
|
541
|
$ob->protocol($http_version); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
58
|
|
|
|
|
298
|
$ob->{_warc_defer}{request} = 1; |
76
|
|
|
|
|
|
|
|
77
|
58
|
|
|
|
|
200
|
WARC::Record::Replay::HTTP::Message::_load_record($ob, $record, $handle); |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
## overridden methods for deferred loading of requests and redirects |
81
|
|
|
|
|
|
|
sub request { |
82
|
9
|
|
|
9
|
1
|
6109
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
9
|
100
|
100
|
|
|
45
|
if ($self->{_warc_defer}{request} && $self->{_warc_record}{collection}) { |
85
|
|
|
|
|
|
|
# replay other record |
86
|
7
|
|
|
|
|
21
|
my $timestamp = $self->{_warc_record}->date; |
87
|
9
|
100
|
|
|
|
59
|
my @requests = grep { $_->type eq 'request' and $_->date <= $timestamp } |
88
|
|
|
|
|
|
|
($self->{_warc_record}{collection}->search |
89
|
7
|
|
|
|
|
28
|
(record_id => $self->{_warc_record}->fields->{'WARC-Concurrent-To'}, |
90
|
|
|
|
|
|
|
time => $timestamp)); # sorted by nearest timestamp |
91
|
|
|
|
|
|
|
# filter removes all records after "this" record |
92
|
|
|
|
|
|
|
# Therefore the list is sorted/filtered to "timestamp descending" |
93
|
7
|
|
|
|
|
203
|
my $record = $requests[0]; # use latest record from the list |
94
|
|
|
|
|
|
|
|
95
|
7
|
100
|
|
|
|
28
|
$self->SUPER::request($record->replay) if $record; |
96
|
7
|
|
|
|
|
99
|
$self->{_warc_defer}{request} = 0; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
9
|
|
|
|
|
34
|
return $self->SUPER::request(@_) |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub previous { |
103
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# This is a stub until a good way to find these is found. |
106
|
|
|
|
|
|
|
# Additional metadata and/or index support will probably be needed. |
107
|
|
|
|
|
|
|
# Lack of support is documented in WARC::Record::Replay::HTTP. |
108
|
|
|
|
|
|
|
|
109
|
1
|
|
|
|
|
11
|
return $self->SUPER::previous(@_) |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1; |
113
|
|
|
|
|
|
|
__END__ |