line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::HeaderParser::XS; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
49037
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
36
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
128
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
1
|
|
|
1
|
|
1614
|
use AutoLoader; |
|
1
|
|
|
|
|
1742
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw( Exporter ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
14
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
15
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# This allows declaration use HTTPHeaders ':all'; |
18
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
19
|
|
|
|
|
|
|
# will save memory. |
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
21
|
|
|
|
|
|
|
H_REQUEST |
22
|
|
|
|
|
|
|
H_RESPONSE |
23
|
|
|
|
|
|
|
M_DELETE |
24
|
|
|
|
|
|
|
M_GET |
25
|
|
|
|
|
|
|
M_OPTIONS |
26
|
|
|
|
|
|
|
M_POST |
27
|
|
|
|
|
|
|
M_PUT |
28
|
|
|
|
|
|
|
M_HEAD |
29
|
|
|
|
|
|
|
) ] ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
our @EXPORT = qw( |
34
|
|
|
|
|
|
|
H_REQUEST |
35
|
|
|
|
|
|
|
H_RESPONSE |
36
|
|
|
|
|
|
|
M_DELETE |
37
|
|
|
|
|
|
|
M_GET |
38
|
|
|
|
|
|
|
M_OPTIONS |
39
|
|
|
|
|
|
|
M_POST |
40
|
|
|
|
|
|
|
M_PUT |
41
|
|
|
|
|
|
|
M_HEAD |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
our $VERSION = '0.20'; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
our $HTTPCode = { |
47
|
|
|
|
|
|
|
200 => 'OK', |
48
|
|
|
|
|
|
|
204 => 'No Content', |
49
|
|
|
|
|
|
|
206 => 'Partial Content', |
50
|
|
|
|
|
|
|
304 => 'Not Modified', |
51
|
|
|
|
|
|
|
400 => 'Bad request', |
52
|
|
|
|
|
|
|
403 => 'Forbidden', |
53
|
|
|
|
|
|
|
404 => 'Not Found', |
54
|
|
|
|
|
|
|
416 => 'Request range not satisfiable', |
55
|
|
|
|
|
|
|
500 => 'Internal Server Error', |
56
|
|
|
|
|
|
|
501 => 'Not Implemented', |
57
|
|
|
|
|
|
|
503 => 'Service Unavailable', |
58
|
|
|
|
|
|
|
}; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub AUTOLOAD { |
61
|
|
|
|
|
|
|
# This AUTOLOAD is used to 'autoload' constants from the constant() |
62
|
|
|
|
|
|
|
# XS function. |
63
|
|
|
|
|
|
|
|
64
|
8
|
|
|
8
|
|
425
|
my $constname; |
65
|
8
|
|
|
|
|
10
|
our $AUTOLOAD; |
66
|
8
|
|
|
|
|
39
|
($constname = $AUTOLOAD) =~ s/.*:://; |
67
|
8
|
50
|
|
|
|
20
|
croak "&HTTP::HeaderParser::XS::constant not defined" if $constname eq 'constant'; |
68
|
8
|
|
|
|
|
24
|
my ($error, $val) = constant($constname); |
69
|
8
|
50
|
|
|
|
14
|
if ($error) { croak $error; } |
|
0
|
|
|
|
|
0
|
|
70
|
|
|
|
|
|
|
{ |
71
|
1
|
|
|
1
|
|
294
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
750
|
|
|
8
|
|
|
|
|
8
|
|
72
|
|
|
|
|
|
|
# Fixed between 5.005_53 and 5.005_61 |
73
|
|
|
|
|
|
|
#XXX if ($] >= 5.00561) { |
74
|
|
|
|
|
|
|
#XXX *$AUTOLOAD = sub () { $val }; |
75
|
|
|
|
|
|
|
#XXX } |
76
|
|
|
|
|
|
|
#XXX else { |
77
|
8
|
|
|
8
|
|
48
|
*$AUTOLOAD = sub { $val }; |
|
8
|
|
|
|
|
104
|
|
78
|
|
|
|
|
|
|
#XXX } |
79
|
|
|
|
|
|
|
} |
80
|
8
|
|
|
|
|
31
|
goto &$AUTOLOAD; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
require XSLoader; |
84
|
|
|
|
|
|
|
XSLoader::load('HTTP::HeaderParser::XS', $VERSION); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# create a very bare response to send to a user (mostly used internally) |
87
|
|
|
|
|
|
|
sub new_response { |
88
|
2
|
|
|
2
|
0
|
15422
|
my $code = $_[1]; |
89
|
|
|
|
|
|
|
|
90
|
2
|
|
50
|
|
|
14
|
my $msg = $HTTPCode->{$code} || ""; |
91
|
2
|
|
|
|
|
19
|
my $hdr = HTTP::HeaderParser::XS->new(\"HTTP/1.0 $code $msg\r\n\r\n"); |
92
|
2
|
|
|
|
|
7
|
return $hdr; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# do some magic to determine content length |
96
|
|
|
|
|
|
|
sub content_length { |
97
|
0
|
|
|
0
|
0
|
0
|
my HTTP::HeaderParser::XS $self = $_[0]; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
0
|
if ($self->isRequest()) { |
100
|
0
|
0
|
|
|
|
0
|
return 0 if $self->getMethod() == M_HEAD(); |
101
|
|
|
|
|
|
|
} else { |
102
|
0
|
|
|
|
|
0
|
my $code = $self->getStatusCode(); |
103
|
0
|
0
|
0
|
|
|
0
|
if ($code == 304 || $code == 204 || ($code >= 100 && $code <= 199)) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
104
|
0
|
|
|
|
|
0
|
return 0; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
0
|
if (defined (my $clen = $self->getHeader('Content-length'))) { |
109
|
0
|
|
|
|
|
0
|
return $clen+0; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
return undef; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub set_version { |
116
|
0
|
|
|
0
|
0
|
0
|
my HTTP::HeaderParser::XS $self = $_[0]; |
117
|
0
|
|
|
|
|
0
|
my $ver = $_[1]; |
118
|
|
|
|
|
|
|
|
119
|
0
|
0
|
|
|
|
0
|
die "Bogus version" unless $ver =~ /^(\d+)\.(\d+)$/; |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
0
|
my ($ver_ma, $ver_mi) = ($1, $2); |
122
|
0
|
|
|
|
|
0
|
$self->setVersionNumber($ver_ma * 1000 + $ver_mi); |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
0
|
return $self; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub clone { |
128
|
0
|
|
|
0
|
0
|
0
|
return HTTP::HeaderParser::XS->new( $_[0]->to_string_ref ); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub code { |
132
|
1
|
|
|
1
|
0
|
269
|
my HTTP::HeaderParser::XS $self = shift; |
133
|
|
|
|
|
|
|
|
134
|
1
|
|
|
|
|
3
|
my ($code, $msg) = @_; |
135
|
1
|
|
33
|
|
|
9
|
$msg ||= $self->http_code_english($code); |
136
|
1
|
|
|
|
|
19
|
$self->setCodeText($code, $msg); |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub http_code_english { |
140
|
1
|
|
|
1
|
0
|
2
|
my HTTP::HeaderParser::XS $self = shift; |
141
|
1
|
50
|
|
|
|
7
|
if (@_) { |
142
|
1
|
|
50
|
|
|
11
|
return $HTTPCode->{shift()} || ""; |
143
|
|
|
|
|
|
|
} else { |
144
|
0
|
0
|
|
|
|
|
return "" unless $self->response_code; |
145
|
0
|
|
0
|
|
|
|
return $HTTPCode->{$self->response_code} || ""; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
# Preloaded methods go here. |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
154
|
|
|
|
|
|
|
__END__ |