line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Apache2::RequestRec; |
2
|
9
|
|
|
9
|
|
79597
|
use strict; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
267
|
|
3
|
9
|
|
|
9
|
|
46
|
use warnings; |
|
9
|
|
|
|
|
13
|
|
|
9
|
|
|
|
|
304
|
|
4
|
9
|
|
|
9
|
|
41
|
use base qw(Test::Apache2::RequestUtil); |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
14756
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use URI; |
7
|
|
|
|
|
|
|
use APR::Pool; |
8
|
|
|
|
|
|
|
use APR::Table; |
9
|
|
|
|
|
|
|
use Scalar::Util; |
10
|
|
|
|
|
|
|
use HTTP::Response; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( |
13
|
|
|
|
|
|
|
qw(status) |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
__PACKAGE__->mk_ro_accessors( |
16
|
|
|
|
|
|
|
qw(headers_in headers_out err_headers_out |
17
|
|
|
|
|
|
|
method content response_body pool) |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
|
|
|
|
|
|
my ($class, @args) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
if (Scalar::Util::blessed($args[0])) { |
24
|
|
|
|
|
|
|
$class->_new_from_request(@args); |
25
|
|
|
|
|
|
|
} else { |
26
|
|
|
|
|
|
|
$class->_new_from_hash_ref(@args); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _new_from_hash_ref { |
31
|
|
|
|
|
|
|
my ($class, @args) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $self = $class->SUPER::new(@args); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
if (@args) { |
36
|
|
|
|
|
|
|
$self->{_real_uri} = URI->new($args[0]->{uri}); |
37
|
|
|
|
|
|
|
} else { |
38
|
|
|
|
|
|
|
$self->{_real_uri} = URI->new('http://example.com/'); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $pool = APR::Pool->new; |
42
|
|
|
|
|
|
|
map { |
43
|
|
|
|
|
|
|
$self->{ $_ } = APR::Table::make($pool, 0); |
44
|
|
|
|
|
|
|
} qw(headers_out err_headers_out subprocess_env); |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $headers_in = APR::Table::make($pool, 0); |
47
|
|
|
|
|
|
|
while (my ($key, $value) = each %{ $self->{headers_in} }) { |
48
|
|
|
|
|
|
|
$headers_in->set($key => $value); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
$self->{headers_in} = $headers_in; |
51
|
|
|
|
|
|
|
$self->{pool} = $pool; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
if (! defined $self->location) { |
54
|
|
|
|
|
|
|
$self->location($self->uri); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
return $self; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _new_from_request { |
61
|
|
|
|
|
|
|
my ($class, $req) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
my %headers_in = map { |
64
|
|
|
|
|
|
|
$_ => $req->header($_); |
65
|
|
|
|
|
|
|
} $req->header_field_names; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
return $class->new({ |
68
|
|
|
|
|
|
|
method => $req->method, |
69
|
|
|
|
|
|
|
uri => $req->uri, |
70
|
|
|
|
|
|
|
headers_in => \%headers_in, |
71
|
|
|
|
|
|
|
content => $req->content, |
72
|
|
|
|
|
|
|
}); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub uri { |
76
|
|
|
|
|
|
|
my ($self) = @_; |
77
|
|
|
|
|
|
|
$self->{_real_uri}->path; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub unparsed_uri { |
81
|
|
|
|
|
|
|
my ($self) = @_; |
82
|
|
|
|
|
|
|
$self->{_real_uri}->path_query; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub get_server_port { |
86
|
|
|
|
|
|
|
my ($self) = @_; |
87
|
|
|
|
|
|
|
$self->{_real_uri}->port; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub hostname { |
91
|
|
|
|
|
|
|
my ($self) = @_; |
92
|
|
|
|
|
|
|
$self->{_real_uri}->host; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub path_info { |
96
|
|
|
|
|
|
|
my $self = shift; |
97
|
|
|
|
|
|
|
my $path_info = $self->uri->path; |
98
|
|
|
|
|
|
|
$self->uri->path(shift()) if @_; |
99
|
|
|
|
|
|
|
return $path_info; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub path { |
103
|
|
|
|
|
|
|
my ($self) = @_; |
104
|
|
|
|
|
|
|
$self->{_real_uri}->path_query; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub header_in { |
108
|
|
|
|
|
|
|
my ($self, $key) = @_; |
109
|
|
|
|
|
|
|
return $self->headers_in->get($key); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
sub header_out { |
113
|
|
|
|
|
|
|
my ($self, $key, $value) = @_; |
114
|
|
|
|
|
|
|
return $self->headers_out->set($key, $value); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub content_type { |
118
|
|
|
|
|
|
|
my $self = shift; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
$self->headers_out->set('Content-Type', shift) if @_; |
121
|
|
|
|
|
|
|
return $self->headers_out->get('Content-Type'); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub send_http_header { |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub subprocess_env { |
128
|
|
|
|
|
|
|
my ($self, $key, $value) = @_; |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
if ($value) { |
131
|
|
|
|
|
|
|
$self->subprocess_env->set($key, $value); |
132
|
|
|
|
|
|
|
} elsif ($key) { |
133
|
|
|
|
|
|
|
$self->subprocess_env->get($key); |
134
|
|
|
|
|
|
|
} else { |
135
|
|
|
|
|
|
|
$self->{subprocess_env}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub args { |
140
|
|
|
|
|
|
|
my ($self, $value) = @_; |
141
|
|
|
|
|
|
|
if (defined $value) { |
142
|
|
|
|
|
|
|
$self->{_real_uri}->query($value); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
return $self->{_real_uri}->query; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub set_content_length { |
148
|
|
|
|
|
|
|
; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub to_response { |
152
|
|
|
|
|
|
|
my ($self) = @_; |
153
|
|
|
|
|
|
|
my $result = HTTP::Response->new; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$self->headers_out->do(sub { |
156
|
|
|
|
|
|
|
$result->header($_[0], $_[1]); |
157
|
|
|
|
|
|
|
return 1; |
158
|
|
|
|
|
|
|
}); |
159
|
|
|
|
|
|
|
$result->code($self->status); |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# TODO: don't access superclass's variable directly |
162
|
|
|
|
|
|
|
$self->{response_body_io}->close; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$result->content($self->response_body); |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
return $result; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
1; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 NAME |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Test::Apache2::RequestRec - Fake Apache2::RequestRec |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head1 DESCRIPTION |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Apache2::RequestRec don't allow you to create an instance manually, |
179
|
|
|
|
|
|
|
because the instance created automatically by mod_perl. |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
So this class provides same interface as Apache2::RequestRec |
182
|
|
|
|
|
|
|
except a public constructor and some setters. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=head1 SEE ALSO |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
L |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |