Filename | /var/www/foswiki11/lib/Foswiki/Request.pm |
Statements | Executed 1382 statements in 11.4ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
207 | 33 | 15 | 2.30ms | 5.24ms | param | Foswiki::Request::
1 | 1 | 1 | 767µs | 6.30ms | BEGIN@37 | Foswiki::Request::
5 | 3 | 3 | 139µs | 385µs | queryString | Foswiki::Request::
3 | 3 | 3 | 104µs | 491µs | url | Foswiki::Request::
6 | 2 | 1 | 80µs | 135µs | header | Foswiki::Request::
4 | 4 | 3 | 27µs | 27µs | action | Foswiki::Request::
1 | 1 | 1 | 20µs | 20µs | new | Foswiki::Request::
6 | 4 | 4 | 20µs | 20µs | pathInfo | Foswiki::Request::
1 | 1 | 1 | 16µs | 33µs | BEGIN@29 | Foswiki::Request::
2 | 2 | 2 | 16µs | 75µs | userAgent | Foswiki::Request::
2 | 2 | 2 | 15µs | 15µs | delete | Foswiki::Request::
1 | 1 | 1 | 14µs | 21µs | BEGIN@30 | Foswiki::Request::
1 | 1 | 1 | 13µs | 32µs | BEGIN@38 | Foswiki::Request::
2 | 2 | 2 | 11µs | 11µs | remoteAddress | Foswiki::Request::
1 | 1 | 1 | 10µs | 26µs | BEGIN@35 | Foswiki::Request::
3 | 3 | 3 | 7µs | 7µs | remoteUser | Foswiki::Request::
1 | 1 | 1 | 4µs | 4µs | BEGIN@32 | Foswiki::Request::
1 | 1 | 1 | 4µs | 4µs | uri | Foswiki::Request::
1 | 1 | 1 | 4µs | 4µs | BEGIN@36 | Foswiki::Request::
1 | 1 | 1 | 3µs | 3µs | method | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | base_action | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | bodyParam | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | cookie | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | cookies | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | deleteAll | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | http | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | https | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | load | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | protocol | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | queryParam | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | referer | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | save | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | secure | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | serverPort | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | tmpFileName | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | upload | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | uploadInfo | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | uploads | Foswiki::Request::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+!! package Foswiki::Request | ||||
6 | |||||
7 | Class to encapsulate request data. | ||||
8 | |||||
9 | Fields: | ||||
10 | * =action= action requested (view, edit, save, ...) | ||||
11 | * =cookies= hashref whose keys are cookie names and values | ||||
12 | are CGI::Cookie objects | ||||
13 | * =headers= hashref whose keys are header name | ||||
14 | * =method= request method (GET, HEAD, POST) | ||||
15 | * =param= hashref of parameters, both query and body ones | ||||
16 | * =param_list= arrayref with parameter names in received order | ||||
17 | * =path_info= path_info of request (eg. /WebName/TopciName) | ||||
18 | * =remote_address= Client's IP address | ||||
19 | * =remote_user= Remote HTTP authenticated user | ||||
20 | * =secure= Boolean value about use of encryption | ||||
21 | * =server_port= Port that the webserver listens on | ||||
22 | * =uploads= hashref whose keys are parameter name of uploaded | ||||
23 | files | ||||
24 | * =uri= the request uri | ||||
25 | |||||
26 | =cut | ||||
27 | |||||
28 | package Foswiki::Request; | ||||
29 | 2 | 34µs | 2 | 50µs | # spent 33µs (16+17) within Foswiki::Request::BEGIN@29 which was called:
# once (16µs+17µs) by Foswiki::Engine::CLI::BEGIN@23 at line 29 # spent 33µs making 1 call to Foswiki::Request::BEGIN@29
# spent 17µs making 1 call to strict::import |
30 | 2 | 35µs | 2 | 28µs | # spent 21µs (14+7) within Foswiki::Request::BEGIN@30 which was called:
# once (14µs+7µs) by Foswiki::Engine::CLI::BEGIN@23 at line 30 # spent 21µs making 1 call to Foswiki::Request::BEGIN@30
# spent 7µs making 1 call to warnings::import |
31 | |||||
32 | 2 | 44µs | 1 | 4µs | # spent 4µs within Foswiki::Request::BEGIN@32 which was called:
# once (4µs+0s) by Foswiki::Engine::CLI::BEGIN@23 at line 32 # spent 4µs making 1 call to Foswiki::Request::BEGIN@32 |
33 | 1 | 9µs | our @ISA = ('CGI'); | ||
34 | |||||
35 | 2 | 28µs | 2 | 42µs | # spent 26µs (10+16) within Foswiki::Request::BEGIN@35 which was called:
# once (10µs+16µs) by Foswiki::Engine::CLI::BEGIN@23 at line 35 # spent 26µs making 1 call to Foswiki::Request::BEGIN@35
# spent 16µs making 1 call to Assert::import |
36 | 2 | 25µs | 1 | 4µs | # spent 4µs within Foswiki::Request::BEGIN@36 which was called:
# once (4µs+0s) by Foswiki::Engine::CLI::BEGIN@23 at line 36 # spent 4µs making 1 call to Foswiki::Request::BEGIN@36 |
37 | 2 | 191µs | 1 | 6.30ms | # spent 6.30ms (767µs+5.53) within Foswiki::Request::BEGIN@37 which was called:
# once (767µs+5.53ms) by Foswiki::Engine::CLI::BEGIN@23 at line 37 # spent 6.30ms making 1 call to Foswiki::Request::BEGIN@37 |
38 | 2 | 2.38ms | 2 | 51µs | # spent 32µs (13+19) within Foswiki::Request::BEGIN@38 which was called:
# once (13µs+19µs) by Foswiki::Engine::CLI::BEGIN@23 at line 38 # spent 32µs making 1 call to Foswiki::Request::BEGIN@38
# spent 19µs making 1 call to Exporter::import |
39 | |||||
40 | =begin TML | ||||
41 | |||||
42 | ---++ ClassMethod new([$initializer]) | ||||
43 | |||||
44 | Constructs a Foswiki::Request object. | ||||
45 | * =$initializer= - may be a filehandle or hashref. | ||||
46 | * If it's a filehandle, it'll be used to reload the Foswiki::Request | ||||
47 | object. See =save= method. Note: Restore only parameters | ||||
48 | * It can be a hashref whose keys are parameter names. Values may be | ||||
49 | arrayref's to multivalued parameters. Same note as above. | ||||
50 | |||||
51 | =cut | ||||
52 | |||||
53 | # spent 20µs within Foswiki::Request::new which was called:
# once (20µs+0s) by Foswiki::Engine::__ANON__[/var/www/foswiki11/lib/Foswiki/Engine.pm:77] at line 68 of /var/www/foswiki11/lib/Foswiki/Engine.pm | ||||
54 | 1 | 1µs | my ( $proto, $initializer ) = @_; | ||
55 | |||||
56 | 1 | 200ns | my $this; | ||
57 | |||||
58 | 1 | 800ns | my $class = ref($proto) || $proto; | ||
59 | |||||
60 | 1 | 9µs | $this = { | ||
61 | action => '', | ||||
62 | cookies => {}, | ||||
63 | headers => {}, | ||||
64 | method => undef, | ||||
65 | param => {}, | ||||
66 | param_list => [], | ||||
67 | path_info => '', | ||||
68 | remote_address => '', | ||||
69 | remote_user => undef, | ||||
70 | secure => 0, | ||||
71 | server_port => undef, | ||||
72 | uploads => {}, | ||||
73 | uri => '', | ||||
74 | }; | ||||
75 | |||||
76 | 1 | 5µs | bless $this, $class; | ||
77 | |||||
78 | 1 | 1µs | if ( ref($initializer) eq 'HASH' ) { | ||
79 | while ( my ( $key, $value ) = each %$initializer ) { | ||||
80 | $this->param( | ||||
81 | -name => $key, | ||||
82 | -value => ref($value) eq 'ARRAY' ? [@$value] : [$value] | ||||
83 | ); | ||||
84 | } | ||||
85 | } | ||||
86 | elsif ( ref($initializer) && UNIVERSAL::isa( $initializer, 'GLOB' ) ) { | ||||
87 | $this->load($initializer); | ||||
88 | } | ||||
89 | 1 | 5µs | return $this; | ||
90 | } | ||||
91 | |||||
92 | =begin TML | ||||
93 | |||||
94 | ---++ ObjectMethod action([$action]) -> $action | ||||
95 | |||||
96 | |||||
97 | Gets/Sets action requested (view, edit, save, ...) | ||||
98 | |||||
99 | =cut | ||||
100 | |||||
101 | # spent 27µs within Foswiki::Request::action which was called 4 times, avg 7µs/call:
# once (9µs+0s) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki.pm:267] at line 267 of /var/www/foswiki11/lib/Foswiki.pm
# once (8µs+0s) by Foswiki::generateHTTPHeaders at line 1033 of /var/www/foswiki11/lib/Foswiki.pm
# once (7µs+0s) by Foswiki::Engine::CLI::preparePath at line 86 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm
# once (2µs+0s) by Foswiki::UI::handleRequest at line 179 of /var/www/foswiki11/lib/Foswiki/UI.pm | ||||
102 | 4 | 4µs | my ( $this, $action ) = @_; | ||
103 | 4 | 2µs | if ( defined $action ) { | ||
104 | |||||
105 | # Record the very first action set in this request. It will be required | ||||
106 | # later if a redirect cache overlays this request. | ||||
107 | 1 | 1µs | $this->{base_action} = $action unless defined $this->{base_action}; | ||
108 | 1 | 3µs | $ENV{FOSWIKI_ACTION} = $this->{action} = $action; | ||
109 | 1 | 5.88ms | return $action; | ||
110 | } | ||||
111 | else { | ||||
112 | 3 | 19µs | return $this->{action}; | ||
113 | } | ||||
114 | |||||
115 | } | ||||
116 | |||||
117 | =begin TML | ||||
118 | |||||
119 | ---++ ObjectMethod base_action() -> $action | ||||
120 | |||||
121 | Get the first action ever set in this request object. This remains | ||||
122 | unchanged even if a request cache is unwrapped on to of this request. | ||||
123 | The idea is that callers can always find out the action that initiated | ||||
124 | the HTTP request. This is required for (for example) checking access | ||||
125 | controls. | ||||
126 | |||||
127 | =cut | ||||
128 | |||||
129 | sub base_action { | ||||
130 | my $this = shift; | ||||
131 | return defined $this->{base_action} | ||||
132 | ? $this->{base_action} | ||||
133 | : $this->action(); | ||||
134 | } | ||||
135 | |||||
136 | =begin TML | ||||
137 | |||||
138 | ---++ ObjectMethod method( [ $method ] ) -> $method | ||||
139 | |||||
140 | Sets/Gets request method (GET, HEAD, POST). | ||||
141 | |||||
142 | =cut | ||||
143 | |||||
144 | # spent 3µs within Foswiki::Request::method which was called:
# once (3µs+0s) by Foswiki::Engine::CLI::prepareConnection at line 61 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm | ||||
145 | 1 | 5µs | return @_ == 1 ? $_[0]->{method} : ( $_[0]->{method} = $_[1] ); | ||
146 | } | ||||
147 | |||||
148 | =begin TML | ||||
149 | |||||
150 | ---++ ObjectMethod pathInfo( [ $path ] ) -> $path | ||||
151 | |||||
152 | Sets/Gets request path info. | ||||
153 | |||||
154 | Called without parameters returns current pathInfo. | ||||
155 | |||||
156 | There is a =path_info()= alias for compatibility with CGI. | ||||
157 | |||||
158 | =cut | ||||
159 | |||||
160 | 1 | 2µs | *path_info = \&pathInfo; | ||
161 | |||||
162 | # spent 20µs within Foswiki::Request::pathInfo which was called 6 times, avg 3µs/call:
# 3 times (12µs+0s) by Foswiki::Request::url at line 250, avg 4µs/call
# once (4µs+0s) by Foswiki::UI::handleRequest at line 224 of /var/www/foswiki11/lib/Foswiki/UI.pm
# once (3µs+0s) by Foswiki::new at line 1860 of /var/www/foswiki11/lib/Foswiki.pm
# once (2µs+0s) by Foswiki::Plugin::load at line 196 of /var/www/foswiki11/lib/Foswiki/Plugin.pm | ||||
163 | 6 | 27µs | return @_ == 1 ? $_[0]->{path_info} : ( $_[0]->{path_info} = $_[1] ); | ||
164 | } | ||||
165 | |||||
166 | =begin TML | ||||
167 | |||||
168 | ---++ ObjectMethod protocol() -> $protocol | ||||
169 | |||||
170 | Returns 'https' if secure connection. 'http' otherwise. | ||||
171 | |||||
172 | =cut | ||||
173 | |||||
174 | # SMELL : review this | ||||
175 | sub protocol { | ||||
176 | return $_[0]->secure ? 'https' : 'http'; | ||||
177 | } | ||||
178 | |||||
179 | =begin TML | ||||
180 | |||||
181 | ---++ ObjectMethod uri( [$uri] ) -> $uri | ||||
182 | |||||
183 | Gets/Sets request uri. | ||||
184 | |||||
185 | =cut | ||||
186 | |||||
187 | # spent 4µs within Foswiki::Request::uri which was called:
# once (4µs+0s) by Foswiki::generateHTTPHeaders at line 1034 of /var/www/foswiki11/lib/Foswiki.pm | ||||
188 | 1 | 6µs | return @_ == 1 ? $_[0]->{uri} : ( $_[0]->{uri} = $_[1] ); | ||
189 | } | ||||
190 | |||||
191 | =begin TML | ||||
192 | |||||
193 | ---++ ObjectMethod queryString() -> $query_string | ||||
194 | |||||
195 | Returns query_string part of request uri, if any. | ||||
196 | |||||
197 | =query_string()= alias provided for compatibility with CGI. | ||||
198 | |||||
199 | =cut | ||||
200 | |||||
201 | 1 | 500ns | *query_string = \&queryString; | ||
202 | |||||
203 | # spent 385µs (139+246) within Foswiki::Request::queryString which was called 5 times, avg 77µs/call:
# 3 times (88µs+151µs) by Foswiki::Request::url at line 279, avg 80µs/call
# once (31µs+53µs) by Foswiki::__ANON__[/var/www/foswiki11/lib/Foswiki.pm:244] at line 244 of /var/www/foswiki11/lib/Foswiki.pm
# once (20µs+42µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1864 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm | ||||
204 | 5 | 2µs | my $this = shift; | ||
205 | 5 | 1µs | my @params; | ||
206 | 5 | 12µs | 5 | 63µs | foreach my $name ( $this->param ) { # spent 63µs making 5 calls to Foswiki::Request::param, avg 13µs/call |
207 | 10 | 17µs | 10 | 27µs | my $key = Foswiki::urlEncode($name); # spent 27µs making 10 calls to Foswiki::urlEncode, avg 3µs/call |
208 | 10 | 17µs | 10 | 17µs | push @params, # spent 17µs making 10 calls to Foswiki::urlEncode, avg 2µs/call |
209 | 10 | 34µs | 10 | 138µs | map { $key . "=" . Foswiki::urlEncode( defined $_ ? $_ : '' ) } # spent 138µs making 10 calls to Foswiki::Request::param, avg 14µs/call |
210 | $this->param($name); | ||||
211 | } | ||||
212 | 5 | 21µs | return join( ';', @params ); | ||
213 | } | ||||
214 | |||||
215 | =begin TML | ||||
216 | |||||
217 | ---++ ObjectMethod url( [-full => 1, | ||||
218 | -base => 1, | ||||
219 | -absolute => 1, | ||||
220 | -relative => 1, | ||||
221 | -path => 1, | ||||
222 | -query => 1] ) -> $url | ||||
223 | |||||
224 | Returns many url info. | ||||
225 | * If called without parameters or with -full => 1 returns full url, e.g. | ||||
226 | http://mysite.net/view | ||||
227 | * If called with -base => 1 returns base url, e.g. http://fosiki.org | ||||
228 | * -absolute => 1 returns absolute action path, e.g. /cgi-bin/view | ||||
229 | * -relative => 1 returns relative action path, e.g. view | ||||
230 | * -path => 1, -query => 1 also includes path info and query string | ||||
231 | respectively | ||||
232 | |||||
233 | Reasonably compatible with CGI corresponding method. Doesn't support | ||||
234 | -rewrite. See Item5914. | ||||
235 | |||||
236 | =cut | ||||
237 | |||||
238 | # spent 491µs (104+387) within Foswiki::Request::url which was called 3 times, avg 164µs/call:
# once (40µs+144µs) by Foswiki::Plugin::load at line 196 of /var/www/foswiki11/lib/Foswiki/Plugin.pm
# once (35µs+122µs) by Foswiki::new at line 1767 of /var/www/foswiki11/lib/Foswiki.pm
# once (30µs+121µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1863 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm | ||||
239 | 3 | 5µs | my ( $this, @p ) = @_; | ||
240 | |||||
241 | 3 | 18µs | 3 | 61µs | my ( $relative, $absolute, $full, $base, $path_info, $query ) = rearrange( # spent 61µs making 3 calls to CGI::Util::rearrange, avg 20µs/call |
242 | [ | ||||
243 | qw(RELATIVE ABSOLUTE FULL BASE), [qw(PATH PATH_INFO)], | ||||
244 | [qw(QUERY_STRING QUERY)], | ||||
245 | ], | ||||
246 | @p | ||||
247 | ); | ||||
248 | 3 | 700ns | my $url; | ||
249 | 3 | 3µs | $full++ if $base || !( $relative || $absolute ); | ||
250 | 3 | 12µs | 3 | 12µs | my $path = $this->pathInfo; # spent 12µs making 3 calls to Foswiki::Request::pathInfo, avg 4µs/call |
251 | 3 | 600ns | my $name; | ||
252 | |||||
253 | 3 | 10µs | if ( defined $Foswiki::cfg{ScriptUrlPaths}{ $this->{action} } ) { | ||
254 | |||||
255 | # When this is set, it is the complete script path including prefix/suffix. | ||||
256 | $name = $Foswiki::cfg{ScriptUrlPaths}{ $this->{action} }; | ||||
257 | } | ||||
258 | else { | ||||
259 | $name = $Foswiki::cfg{ScriptUrlPath} . '/' . $this->{action}; | ||||
260 | |||||
261 | # Don't add suffix if no script is used. | ||||
262 | $name .= $Foswiki::cfg{ScriptSuffix} if $name; | ||||
263 | } | ||||
264 | 3 | 6µs | $name =~ s(//+)(/)g; | ||
265 | 3 | 3µs | if ($full) { | ||
266 | 2 | 11µs | 4 | 75µs | my $vh = $this->header('X-Forwarded-Host') || $this->header('Host'); # spent 75µs making 4 calls to Foswiki::Request::header, avg 19µs/call |
267 | 2 | 4µs | $url = | ||
268 | $vh ? $this->protocol . '://' . $vh : $Foswiki::cfg{DefaultUrlHost}; | ||||
269 | 2 | 500ns | return $url if $base; | ||
270 | 2 | 2µs | $url .= $name; | ||
271 | } | ||||
272 | elsif ($relative) { | ||||
273 | ($url) = $name =~ m{([^/]+)$}; | ||||
274 | } | ||||
275 | elsif ($absolute) { | ||||
276 | $url = $name; | ||||
277 | } | ||||
278 | 3 | 1µs | $url .= $path if $path_info && defined $path; | ||
279 | 3 | 9µs | 3 | 239µs | my $queryString = $this->queryString(); # spent 239µs making 3 calls to Foswiki::Request::queryString, avg 80µs/call |
280 | 3 | 1µs | $url .= '?' . $queryString if $query && $queryString; | ||
281 | 3 | 1µs | $url = '' unless defined $url; | ||
282 | |||||
283 | 3 | 13µs | return $url; | ||
284 | } | ||||
285 | |||||
286 | =begin TML | ||||
287 | |||||
288 | ---++ ObjectMethod secure( [$secure] ) -> $secure | ||||
289 | |||||
290 | Gets/Sets connection's secure flag. | ||||
291 | |||||
292 | =cut | ||||
293 | |||||
294 | sub secure { | ||||
295 | return @_ == 1 ? $_[0]->{secure} : ( $_[0]->{secure} = $_[1] ); | ||||
296 | } | ||||
297 | |||||
298 | =begin TML | ||||
299 | |||||
300 | ---++ ObjectMethod remoteAddress( [$ip] ) -> $ip | ||||
301 | |||||
302 | Gets/Sets client IP address. | ||||
303 | |||||
304 | =remote_addr()= alias for compatibility with CGI. | ||||
305 | |||||
306 | =cut | ||||
307 | |||||
308 | 1 | 400ns | *remote_addr = \&remoteAddress; | ||
309 | |||||
310 | # spent 11µs within Foswiki::Request::remoteAddress which was called 2 times, avg 5µs/call:
# once (7µs+0s) by Foswiki::logEvent at line 2267 of /var/www/foswiki11/lib/Foswiki.pm
# once (4µs+0s) by Foswiki::Engine::CLI::prepareConnection at line 60 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm | ||||
311 | 2 | 12µs | return @_ == 1 | ||
312 | ? $_[0]->{remote_address} | ||||
313 | : ( $_[0]->{remote_address} = $_[1] ); | ||||
314 | } | ||||
315 | |||||
316 | =begin TML | ||||
317 | |||||
318 | ---++ ObjectMethod remoteUser( [$userName] ) -> $userName | ||||
319 | |||||
320 | Gets/Sets remote user's name. | ||||
321 | |||||
322 | =remote_user()= alias for compatibility with CGI. | ||||
323 | |||||
324 | =cut | ||||
325 | |||||
326 | 1 | 400ns | *remote_user = \&remoteUser; | ||
327 | |||||
328 | # spent 7µs within Foswiki::Request::remoteUser which was called 3 times, avg 2µs/call:
# once (3µs+0s) by Foswiki::Engine::CLI::prepareHeaders at line 80 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm
# once (2µs+0s) by Foswiki::LoginManager::ApacheLogin::getUser at line 144 of /var/www/foswiki11/lib/Foswiki/LoginManager/ApacheLogin.pm
# once (2µs+0s) by Foswiki::UI::__ANON__[/var/www/foswiki11/lib/Foswiki/UI.pm:318] at line 306 of /var/www/foswiki11/lib/Foswiki/UI.pm | ||||
329 | 3 | 13µs | return @_ == 1 ? $_[0]->{remote_user} : ( $_[0]->{remote_user} = $_[1] ); | ||
330 | } | ||||
331 | |||||
332 | =begin TML | ||||
333 | |||||
334 | ---++ ObjectMethod serverPort( [$userName] ) -> $userName | ||||
335 | |||||
336 | Gets/Sets server user's name. | ||||
337 | |||||
338 | =server_port()= alias for compatibility with CGI. | ||||
339 | |||||
340 | =cut | ||||
341 | |||||
342 | 1 | 400ns | *server_port = \&serverPort; | ||
343 | |||||
344 | sub serverPort { | ||||
345 | return @_ == 1 ? $_[0]->{server_port} : ( $_[0]->{server_port} = $_[1] ); | ||||
346 | } | ||||
347 | |||||
348 | =begin TML | ||||
349 | |||||
350 | ---++ ObjectMethod queryParam( [-name => $name, -value => $value | | ||||
351 | -name => $name, -values => [ $v1, $v2, ... ] | | ||||
352 | $name, $v1, $v2, ... | | ||||
353 | name, [ $v1, $v2, ... ] | ||||
354 | ] ) -> @paramNames | @values | $firstValue | ||||
355 | |||||
356 | This methos is used by engines, during its prepare phase. Should not be used | ||||
357 | anywhere else. Since bodyParam must exist and it has different semantics from | ||||
358 | param method, this one exists for symmetry, and could be modified in the | ||||
359 | future, so it could be possible to get query and body parameters independently. | ||||
360 | |||||
361 | =cut | ||||
362 | |||||
363 | sub queryParam { | ||||
364 | my $this = shift; | ||||
365 | return if $this->method && $this->method eq 'POST'; | ||||
366 | return $this->param(@_); | ||||
367 | } | ||||
368 | |||||
369 | =begin TML | ||||
370 | |||||
371 | ---++ ObjectMethod bodyParam( [-name => $name, -value => $value | | ||||
372 | -name => $name, -values => [ $v1, $v2, ... ] | | ||||
373 | $name, $v1, $v2, ... | | ||||
374 | name, [ $v1, $v2, ... ] | ||||
375 | ] ) -> @paramNames | @values | $firstValue | ||||
376 | |||||
377 | Adds parameters passed within request body to the object. Should be called | ||||
378 | only by engines. Otherwise use param() method. | ||||
379 | |||||
380 | =cut | ||||
381 | |||||
382 | sub bodyParam { | ||||
383 | my $this = shift; | ||||
384 | return $this->param(@_); | ||||
385 | } | ||||
386 | |||||
387 | =begin TML | ||||
388 | |||||
389 | ---++ ObjectMethod param( [-name => $name, -value => $value | | ||||
390 | -name => $name, -values => [ $v1, $v2, ... ] | | ||||
391 | $name, $v1, $v2, ... | | ||||
392 | name, [ $v1, $v2, ... ] | ||||
393 | ] ) -> @paramNames | @values | $firstValue | ||||
394 | |||||
395 | * Called without parameters returns all parameter names | ||||
396 | * Called only with parameter name or with -name => 'name' | ||||
397 | * In list context returns all associated values (maybe empty list) | ||||
398 | * In scalar context returns first value (maybe undef) | ||||
399 | * Called with name and list of values or with | ||||
400 | -name => 'name', -value => 'value' or -name => 'name', -values => [ ... ] | ||||
401 | sets parameter value | ||||
402 | |||||
403 | Resonably compatible with CGI. | ||||
404 | |||||
405 | =cut | ||||
406 | |||||
407 | # spent 5.24ms (2.30+2.94) within Foswiki::Request::param which was called 207 times, avg 25µs/call:
# 45 times (815µs+1.15ms) by Foswiki::getSkin at line 1375 of /var/www/foswiki11/lib/Foswiki.pm, avg 44µs/call
# 45 times (389µs+374µs) by Foswiki::getSkin at line 1396 of /var/www/foswiki11/lib/Foswiki.pm, avg 17µs/call
# 41 times (335µs+446µs) by Foswiki::Search::searchWeb at line 277 of /var/www/foswiki11/lib/Foswiki/Search.pm, avg 19µs/call
# 18 times (196µs+254µs) by Foswiki::If::OP_dollar::evaluate at line 35 of /var/www/foswiki11/lib/Foswiki/If/OP_dollar.pm, avg 25µs/call
# 12 times (105µs+138µs) by Foswiki::If::OP_defined::evaluate at line 33 of /var/www/foswiki11/lib/Foswiki/If/OP_defined.pm, avg 20µs/call
# 10 times (69µs+70µs) by Foswiki::Request::queryString at line 209, avg 14µs/call
# 5 times (34µs+30µs) by Foswiki::Request::queryString at line 206, avg 13µs/call
# 3 times (29µs+50µs) by Foswiki::URLPARAM at line 47 of /var/www/foswiki11/lib/Foswiki/Macros/URLPARAM.pm, avg 26µs/call
# 3 times (26µs+33µs) by Foswiki::REVINFO at line 17 of /var/www/foswiki11/lib/Foswiki/Macros/REVINFO.pm, avg 20µs/call
# 2 times (26µs+68µs) by Foswiki::Engine::CLI::prepareQueryParameters at line 67 of /var/www/foswiki11/lib/Foswiki/Engine/CLI.pm, avg 47µs/call
# once (41µs+33µs) by Foswiki::UI::View::view at line 265 of /var/www/foswiki11/lib/Foswiki/UI/View.pm
# once (25µs+34µs) by Foswiki::Plugins::DirectedGraphPlugin::initPlugin at line 147 of /var/www/foswiki11/lib/Foswiki/Plugins/DirectedGraphPlugin.pm
# once (20µs+30µs) by Foswiki::UI::View::view at line 165 of /var/www/foswiki11/lib/Foswiki/UI/View.pm
# once (21µs+28µs) by Foswiki::UI::View::view at line 268 of /var/www/foswiki11/lib/Foswiki/UI/View.pm
# once (19µs+29µs) by Foswiki::Plugins::WysiwygPlugin::modifyHeaderHandler at line 293 of /var/www/foswiki11/lib/Foswiki/Plugins/WysiwygPlugin.pm
# once (18µs+25µs) by Foswiki::Plugins::load at line 134 of /var/www/foswiki11/lib/Foswiki/Plugins.pm
# once (11µs+14µs) by Foswiki::LoginManager::makeLoginManager at line 85 of /var/www/foswiki11/lib/Foswiki/LoginManager.pm
# once (11µs+11µs) by Foswiki::UI::View::view at line 90 of /var/www/foswiki11/lib/Foswiki/UI/View.pm
# once (10µs+12µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1859 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
# once (10µs+11µs) by Foswiki::UI::handleRequest at line 216 of /var/www/foswiki11/lib/Foswiki/UI.pm
# once (8µs+13µs) by Foswiki::Plugins::WysiwygPlugin::beforeCommonTagsHandler at line 281 of /var/www/foswiki11/lib/Foswiki/Plugins/WysiwygPlugin.pm
# once (9µs+10µs) by Foswiki::new at line 1828 of /var/www/foswiki11/lib/Foswiki.pm
# once (9µs+10µs) by Foswiki::UI::View::view at line 228 of /var/www/foswiki11/lib/Foswiki/UI/View.pm
# once (8µs+10µs) by Foswiki::UI::View::view at line 102 of /var/www/foswiki11/lib/Foswiki/UI/View.pm
# once (7µs+8µs) by Foswiki::UI::View::view at line 91 of /var/www/foswiki11/lib/Foswiki/UI/View.pm
# once (7µs+9µs) by Foswiki::Plugins::TablePlugin::Core::_parseAttributes at line 293 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
# once (8µs+8µs) by Foswiki::UI::View::view at line 247 of /var/www/foswiki11/lib/Foswiki/UI/View.pm
# once (7µs+8µs) by Foswiki::LoginManager::loadSession at line 470 of /var/www/foswiki11/lib/Foswiki/LoginManager.pm
# once (6µs+7µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1860 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
# once (6µs+7µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1872 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
# once (5µs+6µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1861 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
# once (6µs+6µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1878 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
# once (5µs+6µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1882 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm | ||||
408 | 207 | 272µs | my ( $this, @p ) = @_; | ||
409 | |||||
410 | 207 | 957µs | 207 | 2.94ms | my ( $key, @value ) = rearrange( [ 'NAME', [qw(VALUE VALUES)] ], @p ); # spent 2.94ms making 207 calls to CGI::Util::rearrange, avg 14µs/call |
411 | |||||
412 | 207 | 93µs | return @{ $this->{param_list} } unless defined $key; | ||
413 | 200 | 57µs | if ( defined $value[0] ) { | ||
414 | 2 | 3µs | push @{ $this->{param_list} }, $key | ||
415 | unless exists $this->{param}{$key}; | ||||
416 | 2 | 2µs | $this->{param}{$key} = ref $value[0] eq 'ARRAY' ? $value[0] : [@value]; | ||
417 | } | ||||
418 | 200 | 469µs | if ( defined $this->{param}{$key} ) { | ||
419 | return wantarray | ||||
420 | ? @{ $this->{param}{$key} } | ||||
421 | : $this->{param}{$key}->[0]; | ||||
422 | } | ||||
423 | else { | ||||
424 | 141 | 499µs | return wantarray ? () : undef; | ||
425 | } | ||||
426 | } | ||||
427 | |||||
428 | =begin TML | ||||
429 | |||||
430 | ---++ ObjectMethod cookie($name [, $value, $path, $secure, $expires]) -> $value | ||||
431 | |||||
432 | * If called without parameters returns a list of cookie names. | ||||
433 | * If called only with =$name= parameter returns value of cookie | ||||
434 | with that name or undef if it doesn't exist. | ||||
435 | * If called with defined $value and other parameters returns a | ||||
436 | CGI::Cookie object created with those parameters. Doesn't | ||||
437 | store this new created cookie within request object. This way | ||||
438 | for compatibility with CGI. | ||||
439 | |||||
440 | =cut | ||||
441 | |||||
442 | sub cookie { | ||||
443 | eval { require CGI::Cookie; 1 } or throw Error::Simple($@); | ||||
444 | my ( $this, @p ) = @_; | ||||
445 | my ( $name, $value, $path, $secure, $expires ) = | ||||
446 | rearrange( [ 'NAME', [qw(VALUE VALUES)], 'PATH', 'SECURE', 'EXPIRES' ], | ||||
447 | @p ); | ||||
448 | unless ( defined $value ) { | ||||
449 | return keys %{ $this->{cookies} } unless $name; | ||||
450 | return () unless $this->{cookies}{$name}; | ||||
451 | return $this->{cookies}{$name}->value if defined $name && $name ne ''; | ||||
452 | } | ||||
453 | return unless defined $name && $name ne ''; | ||||
454 | return new CGI::Cookie( | ||||
455 | -name => $name, | ||||
456 | -value => $value, | ||||
457 | -path => $path || '/', | ||||
458 | -secure => $secure || $this->secure, | ||||
459 | -expires => $expires || abs( $Foswiki::cfg{Sessions}{ExpireAfter} ) | ||||
460 | ); | ||||
461 | } | ||||
462 | |||||
463 | =begin TML | ||||
464 | |||||
465 | ObjectMethod cookies( \%cookies ) -> $hashref | ||||
466 | |||||
467 | Gets/Sets cookies hashref. Keys are cookie names | ||||
468 | and values CGI::Cookie objects. | ||||
469 | |||||
470 | =cut | ||||
471 | |||||
472 | sub cookies { | ||||
473 | return @_ == 1 ? $_[0]->{cookies} : ( $_[0]->{cookies} = $_[1] ); | ||||
474 | } | ||||
475 | |||||
476 | =begin TML | ||||
477 | |||||
478 | ---++ ObjectMethod delete( @paramNames ) | ||||
479 | |||||
480 | Deletes parameters from request. | ||||
481 | |||||
482 | =Delete()= alias provided for compatibility with CGI | ||||
483 | |||||
484 | =cut | ||||
485 | |||||
486 | 1 | 500ns | *Delete = \&delete; | ||
487 | |||||
488 | # spent 15µs within Foswiki::Request::delete which was called 2 times, avg 7µs/call:
# once (9µs+0s) by Foswiki::Plugins::TablePlugin::Core::handler at line 1862 of /var/www/foswiki11/lib/Foswiki/Plugins/TablePlugin/Core.pm
# once (6µs+0s) by Foswiki::LoginManager::loadSession at line 491 of /var/www/foswiki11/lib/Foswiki/LoginManager.pm | ||||
489 | 2 | 1µs | my $this = shift; | ||
490 | 2 | 13µs | foreach my $p (@_) { | ||
491 | 4 | 2µs | next unless exists $this->{param}{$p}; | ||
492 | if ( my $upload = $this->{uploads}{ $this->param($p) } ) { | ||||
493 | $upload->finish; | ||||
494 | CORE::delete $this->{uploads}{ $this->param($p) }; | ||||
495 | } | ||||
496 | CORE::delete $this->{param}{$p}; | ||||
497 | @{ $this->{param_list} } = grep { $_ ne $p } @{ $this->{param_list} }; | ||||
498 | } | ||||
499 | } | ||||
500 | |||||
501 | =begin TML | ||||
502 | |||||
503 | ---++ ObjectMethod deleteAll() | ||||
504 | |||||
505 | Deletes all parameter name and value(s). | ||||
506 | |||||
507 | =delete_all()= alias provided for compatibility with CGI. | ||||
508 | |||||
509 | =cut | ||||
510 | |||||
511 | 1 | 400ns | *delete_all = \&deleteAll; | ||
512 | |||||
513 | sub deleteAll { | ||||
514 | my $this = shift; | ||||
515 | $this->delete( $this->param() ); | ||||
516 | } | ||||
517 | |||||
518 | =begin TML | ||||
519 | |||||
520 | ---++ ObjectMethod header([-name => $name, -value => $value | | ||||
521 | -name => $name, -values => [ $v1, $v2, ... ] | | ||||
522 | $name, $v1, $v2, ... | | ||||
523 | name, [ $v1, $v2, ... ] | ||||
524 | ] ) -> @paramNames | @values | $firstValue | ||||
525 | |||||
526 | Gets/Sets a header field: | ||||
527 | * Called without parameters returns all header field names | ||||
528 | * Called only with header field name or with -name => 'name' | ||||
529 | * In list context returns all associated values (maybe empty list) | ||||
530 | * In scalar context returns the first value (maybe undef) | ||||
531 | * Called with name and list of values or with | ||||
532 | -name => 'name', -value => 'value' or -name => 'name', -values => [ ... ] | ||||
533 | sets header field value | ||||
534 | |||||
535 | *Not compatible with CGI*, since CGI correspondent is a | ||||
536 | response write method. CGI scripts obtain headers from %ENV | ||||
537 | or =http= method. %ENV is not available and must be replaced | ||||
538 | by calls to this and other methods of this class. =http= is | ||||
539 | provided for compatibility, but is deprecated. Use this one | ||||
540 | instead. | ||||
541 | |||||
542 | Calls to CGI =header= method must be replaced by calls to | ||||
543 | Foswiki::Response =header= method. | ||||
544 | |||||
545 | =cut | ||||
546 | |||||
547 | sub header { | ||||
548 | 6 | 9µs | my ( $this, @p ) = @_; | ||
549 | 6 | 23µs | 6 | 55µs | my ( $key, @value ) = rearrange( [ 'NAME', [qw(VALUE VALUES)] ], @p ); # spent 55µs making 6 calls to CGI::Util::rearrange, avg 9µs/call |
550 | |||||
551 | 6 | 2µs | return keys %{ $this->{headers} } unless $key; | ||
552 | 6 | 5µs | $key =~ tr/_/-/; | ||
553 | 6 | 7µs | $key = lc($key); | ||
554 | |||||
555 | 6 | 2µs | if ( defined $value[0] ) { | ||
556 | $this->{headers}{$key} = | ||||
557 | ref $value[0] eq 'ARRAY' ? $value[0] : [@value]; | ||||
558 | } | ||||
559 | 6 | 5µs | if ( defined $this->{headers}{$key} ) { | ||
560 | return wantarray | ||||
561 | ? @{ $this->{headers}{$key} } | ||||
562 | : $this->{headers}{$key}->[0]; | ||||
563 | } | ||||
564 | else { | ||||
565 | 6 | 20µs | return wantarray ? () : undef; | ||
566 | } | ||||
567 | } | ||||
568 | |||||
569 | =begin TML | ||||
570 | |||||
571 | ---++ ObjectMethod save( $fh ) | ||||
572 | |||||
573 | Saves object state to filehandle. Object may be loaded latter | ||||
574 | passing $fh to new constructor or by calling load(). | ||||
575 | |||||
576 | =cut | ||||
577 | |||||
578 | sub save { | ||||
579 | my ( $this, $fh ) = @_; | ||||
580 | local ( $\, $, ) = ( '', '' ); | ||||
581 | foreach my $name ( $this->param ) { | ||||
582 | foreach my $value ( $this->param($name) ) { | ||||
583 | $value = '' unless defined $value; | ||||
584 | next if $name eq '' && $value eq ''; # Item12371 | ||||
585 | print $fh Foswiki::urlEncode($name), '=', | ||||
586 | Foswiki::urlEncode($value), "\n"; | ||||
587 | } | ||||
588 | } | ||||
589 | print $fh "=\n"; | ||||
590 | } | ||||
591 | |||||
592 | =begin TML | ||||
593 | |||||
594 | ---++ ObjectMethod load( $fh ) | ||||
595 | |||||
596 | Loads object state from filehandle, probably created with | ||||
597 | a previous save(). | ||||
598 | |||||
599 | =cut | ||||
600 | |||||
601 | sub load { | ||||
602 | my ( $this, $file ) = @_; | ||||
603 | my %param = (); | ||||
604 | my @plist = (); | ||||
605 | local $/ = "\n"; | ||||
606 | while (<$file>) { | ||||
607 | chomp; | ||||
608 | last if /^=$/; | ||||
609 | my ( $key, $value ) = | ||||
610 | map { defined $_ ? Foswiki::urlDecode($_) : $_ } split /=/; | ||||
611 | if ( exists $param{$key} ) { | ||||
612 | push @{ $param{$key} }, $value; | ||||
613 | } | ||||
614 | else { | ||||
615 | push @plist, $key; | ||||
616 | $param{$key} = [$value]; | ||||
617 | } | ||||
618 | } | ||||
619 | foreach my $key (@plist) { | ||||
620 | $this->param( -name => $key, -value => $param{$key} ); | ||||
621 | } | ||||
622 | } | ||||
623 | |||||
624 | =begin TML | ||||
625 | |||||
626 | ---++ ObjectMethod upload( $name ) -> $handle | ||||
627 | |||||
628 | Called with file name parameter returns an open filehandle | ||||
629 | to uploaded file. | ||||
630 | |||||
631 | =cut | ||||
632 | |||||
633 | sub upload { | ||||
634 | my ( $this, $name ) = @_; | ||||
635 | my $upload = $this->{uploads}{ $this->param($name) }; | ||||
636 | return defined $upload ? $upload->handle : undef; | ||||
637 | } | ||||
638 | |||||
639 | =begin TML | ||||
640 | |||||
641 | ---++ ObjectMethod uploadInfo( $fname ) -> $headers | ||||
642 | |||||
643 | Returns a hashref to information about uploaded | ||||
644 | files as sent by browser. | ||||
645 | |||||
646 | =cut | ||||
647 | |||||
648 | sub uploadInfo { | ||||
649 | return $_[0]->{uploads}{ $_[1] }->uploadInfo; | ||||
650 | } | ||||
651 | |||||
652 | =begin TML | ||||
653 | |||||
654 | ---++ ObjectMethod tmpFileName( $fname ) -> $tmpFileName | ||||
655 | |||||
656 | Returns the name of temporarly created file to store uploaded $fname. | ||||
657 | |||||
658 | $fname may be obtained by calling =param()= with form field name. | ||||
659 | |||||
660 | =cut | ||||
661 | |||||
662 | sub tmpFileName { | ||||
663 | my ( $this, $fname ) = @_; | ||||
664 | return $this->{uploads}{$fname} | ||||
665 | ? $this->{uploads}{$fname}->tmpFileName | ||||
666 | : undef; | ||||
667 | } | ||||
668 | |||||
669 | =begin TML | ||||
670 | |||||
671 | ---++ ObjectMethod uploads( [ \%uploads ] ) -> $hashref | ||||
672 | |||||
673 | Gets/Sets request uploads field. Keys are uploaded file names, | ||||
674 | as sent by browser, and values are Foswiki::Request::Upload objects. | ||||
675 | |||||
676 | =cut | ||||
677 | |||||
678 | sub uploads { | ||||
679 | return @_ == 1 ? $_[0]->{uploads} : ( $_[0]->{uploads} = $_[1] ); | ||||
680 | } | ||||
681 | |||||
682 | # ======== possible accessors ======= | ||||
683 | # auth_type | ||||
684 | # content_length | ||||
685 | # content_type | ||||
686 | |||||
687 | =begin TML | ||||
688 | |||||
689 | ---++ ObjectMethod http( [$header] ) -> $value DEPRECATED | ||||
690 | |||||
691 | Called without parameters returns a list of all available header filed names. | ||||
692 | |||||
693 | Given a field name returns value associated. | ||||
694 | |||||
695 | http('HTTP_USER_AGENT'); http('User-Agent') and http('User_Agent') | ||||
696 | are equivalent. | ||||
697 | |||||
698 | Please, use =header()= instead. Present only for compatibility with CGI. | ||||
699 | |||||
700 | =cut | ||||
701 | |||||
702 | sub http { | ||||
703 | my ( $this, $p ) = @_; | ||||
704 | if ( defined $p ) { | ||||
705 | $p =~ s/^https?[_-]//i; | ||||
706 | return $this->header($p); | ||||
707 | } | ||||
708 | return $this->header(); | ||||
709 | } | ||||
710 | |||||
711 | =begin TML | ||||
712 | |||||
713 | ---++ ObjectMethod https( [$name] ) -> $value || $secure DEPRECATED | ||||
714 | |||||
715 | Similar to =http()= method above. Called with no parameters returns | ||||
716 | secure flag. | ||||
717 | |||||
718 | Please, use =header()= and =secure()= instead. | ||||
719 | Present only for compatibility with CGI. | ||||
720 | |||||
721 | =cut | ||||
722 | |||||
723 | sub https { | ||||
724 | my ( $this, $p ) = @_; | ||||
725 | return !defined $p || $p =~ /^https$/i ? $this->secure : $this->http($p); | ||||
726 | } | ||||
727 | |||||
728 | =begin TML | ||||
729 | |||||
730 | ---++ ObjectMethod userAgent() -> $userAgent; | ||||
731 | |||||
732 | Convenience method to get User-Agent string. | ||||
733 | |||||
734 | =user_agent()= alias provided for compatibility with CGI. | ||||
735 | |||||
736 | =cut | ||||
737 | |||||
738 | 1 | 400ns | *user_agent = \&userAgent; | ||
739 | |||||
740 | 2 | 15µs | 2 | 59µs | # spent 75µs (16+59) within Foswiki::Request::userAgent which was called 2 times, avg 38µs/call:
# once (9µs+32µs) by Foswiki::Plugins::TinyMCEPlugin::initPlugin at line 46 of /var/www/foswiki11/lib/Foswiki/Plugins/TinyMCEPlugin.pm
# once (7µs+28µs) by Foswiki::logEvent at line 2254 of /var/www/foswiki11/lib/Foswiki.pm # spent 59µs making 2 calls to Foswiki::Request::header, avg 30µs/call |
741 | |||||
742 | =begin TML | ||||
743 | |||||
744 | ---++ ObjectMethod referer() | ||||
745 | |||||
746 | Convenience method to get Referer uri. | ||||
747 | |||||
748 | =cut | ||||
749 | |||||
750 | sub referer { shift->header('Referer') } | ||||
751 | |||||
752 | 1 | 8µs | 1; | ||
753 | __END__ |