← Index
NYTProf Performance Profile   « line view »
For ./view
  Run on Fri Jul 31 18:42:36 2015
Reported on Fri Jul 31 18:48:13 2015

Filename/var/www/foswikidev/core/lib/Foswiki/Request.pm
StatementsExecuted 1627 statements in 5.54ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
22532152.29ms5.15msFoswiki::Request::::paramFoswiki::Request::param
1112.03ms3.06msFoswiki::Request::::BEGIN@39Foswiki::Request::BEGIN@39
111627µs5.04msFoswiki::Request::::BEGIN@37Foswiki::Request::BEGIN@37
833192µs745µsFoswiki::Request::::queryStringFoswiki::Request::queryString
644171µs1.08msFoswiki::Request::::urlFoswiki::Request::url
1232117µs212µsFoswiki::Request::::headerFoswiki::Request::header
11126µs38µsFoswiki::Request::::newFoswiki::Request::new
104425µs25µsFoswiki::Request::::pathInfoFoswiki::Request::pathInfo
44321µs21µsFoswiki::Request::::actionFoswiki::Request::action
11121µs32µsFoswiki::Request::::getTimeFoswiki::Request::getTime
11114µs27µsFoswiki::Request::::cookieFoswiki::Request::cookie
11114µs28µsFoswiki::Request::::BEGIN@29Foswiki::Request::BEGIN@29
22212µs12µsFoswiki::Request::::deleteFoswiki::Request::delete
11112µs29µsFoswiki::Request::::BEGIN@38Foswiki::Request::BEGIN@38
33111µs52µsFoswiki::Request::::multi_paramFoswiki::Request::multi_param
1119µs34µsFoswiki::Request::::BEGIN@35Foswiki::Request::BEGIN@35
1119µs14µsFoswiki::Request::::BEGIN@30Foswiki::Request::BEGIN@30
3338µs8µsFoswiki::Request::::remoteUserFoswiki::Request::remoteUser
2227µs7µsFoswiki::Request::::remoteAddressFoswiki::Request::remoteAddress
2226µs6µsFoswiki::Request::::methodFoswiki::Request::method
1116µs28µsFoswiki::Request::::userAgentFoswiki::Request::userAgent
1115µs5µsFoswiki::Request::::BEGIN@41Foswiki::Request::BEGIN@41
1114µs4µsFoswiki::Request::::BEGIN@36Foswiki::Request::BEGIN@36
1114µs4µsFoswiki::Request::::BEGIN@32Foswiki::Request::BEGIN@32
1113µs3µsFoswiki::Request::::uriFoswiki::Request::uri
0000s0sFoswiki::Request::::base_actionFoswiki::Request::base_action
0000s0sFoswiki::Request::::bodyParamFoswiki::Request::bodyParam
0000s0sFoswiki::Request::::cookiesFoswiki::Request::cookies
0000s0sFoswiki::Request::::deleteAllFoswiki::Request::deleteAll
0000s0sFoswiki::Request::::httpFoswiki::Request::http
0000s0sFoswiki::Request::::httpsFoswiki::Request::https
0000s0sFoswiki::Request::::loadFoswiki::Request::load
0000s0sFoswiki::Request::::protocolFoswiki::Request::protocol
0000s0sFoswiki::Request::::queryParamFoswiki::Request::queryParam
0000s0sFoswiki::Request::::refererFoswiki::Request::referer
0000s0sFoswiki::Request::::saveFoswiki::Request::save
0000s0sFoswiki::Request::::secureFoswiki::Request::secure
0000s0sFoswiki::Request::::serverPortFoswiki::Request::serverPort
0000s0sFoswiki::Request::::tmpFileNameFoswiki::Request::tmpFileName
0000s0sFoswiki::Request::::uploadFoswiki::Request::upload
0000s0sFoswiki::Request::::uploadInfoFoswiki::Request::uploadInfo
0000s0sFoswiki::Request::::uploadsFoswiki::Request::uploads
Call graph for these subroutines as a Graphviz dot language file.
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
7Class to encapsulate request data.
8
9Fields:
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
28package Foswiki::Request;
29228µs242µs
# spent 28µs (14+14) within Foswiki::Request::BEGIN@29 which was called: # once (14µs+14µs) by Foswiki::Engine::CLI::BEGIN@23 at line 29
use strict;
# spent 28µs making 1 call to Foswiki::Request::BEGIN@29 # spent 14µs making 1 call to strict::import
30224µs218µs
# spent 14µs (9+5) within Foswiki::Request::BEGIN@30 which was called: # once (9µs+5µs) by Foswiki::Engine::CLI::BEGIN@23 at line 30
use warnings;
# spent 14µs making 1 call to Foswiki::Request::BEGIN@30 # spent 5µs making 1 call to warnings::import
31
32233µs14µ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
use CGI ();
# spent 4µs making 1 call to Foswiki::Request::BEGIN@32
3317µsour @ISA = ('CGI');
34
35225µs259µs
# spent 34µs (9+25) within Foswiki::Request::BEGIN@35 which was called: # once (9µs+25µs) by Foswiki::Engine::CLI::BEGIN@23 at line 35
use Assert;
# spent 34µs making 1 call to Foswiki::Request::BEGIN@35 # spent 25µs making 1 call to Exporter::import
36219µs14µ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
use Error ();
# spent 4µs making 1 call to Foswiki::Request::BEGIN@36
372168µs15.04ms
# spent 5.04ms (627µs+4.41) within Foswiki::Request::BEGIN@37 which was called: # once (627µs+4.41ms) by Foswiki::Engine::CLI::BEGIN@23 at line 37
use IO::File ();
# spent 5.04ms making 1 call to Foswiki::Request::BEGIN@37
38228µs245µs
# spent 29µs (12+17) within Foswiki::Request::BEGIN@38 which was called: # once (12µs+17µs) by Foswiki::Engine::CLI::BEGIN@23 at line 38
use CGI::Util qw(rearrange);
# spent 29µs making 1 call to Foswiki::Request::BEGIN@38 # spent 17µs making 1 call to Exporter::import
392129µs13.06ms
# spent 3.06ms (2.03+1.03) within Foswiki::Request::BEGIN@39 which was called: # once (2.03ms+1.03ms) by Foswiki::Engine::CLI::BEGIN@23 at line 39
use Time::HiRes ();
# spent 3.06ms making 1 call to Foswiki::Request::BEGIN@39
40
41
# spent 5µs within Foswiki::Request::BEGIN@41 which was called: # once (5µs+0s) by Foswiki::Engine::CLI::BEGIN@23 at line 46
BEGIN {
4215µs if ( $Foswiki::cfg{UseLocale} ) {
43 require locale;
44 import locale();
45 }
4612.10ms15µs}
# spent 5µs making 1 call to Foswiki::Request::BEGIN@41
47
48
# spent 32µs (21+11) within Foswiki::Request::getTime which was called: # once (21µs+11µs) by Foswiki::writeCompletePage at line 790 of /var/www/foswikidev/core/lib/Foswiki.pm
sub getTime {
4912µs my $this = shift;
50110µs13µs my $endTime = [Time::HiRes::gettimeofday];
# spent 3µs making 1 call to Time::HiRes::gettimeofday
5116µs18µs my $timeDiff = Time::HiRes::tv_interval( $this->{start_time}, $endTime );
# spent 8µs making 1 call to Time::HiRes::tv_interval
5215µs return $timeDiff;
53}
54
55=begin TML
56
57---++ ClassMethod new([$initializer])
58
59Constructs a Foswiki::Request object.
60 * =$initializer= - may be a filehandle or hashref.
61 * If it's a filehandle, it'll be used to reload the Foswiki::Request
62 object. See =save= method. Note: Restore only parameters
63 * It can be a hashref whose keys are parameter names. Values may be
64 arrayref's to multivalued parameters. Same note as above.
65
66=cut
67
68
# spent 38µs (26+12) within Foswiki::Request::new which was called: # once (26µs+12µs) by Foswiki::Engine::__ANON__[/var/www/foswikidev/core/lib/Foswiki/Engine.pm:110] at line 101 of /var/www/foswikidev/core/lib/Foswiki/Engine.pm
sub new {
6911µs my ( $proto, $initializer ) = @_;
70
711200ns my $this;
72
731900ns my $class = ref($proto) || $proto;
74
75126µs112µs $this = {
# spent 12µs making 1 call to Time::HiRes::gettimeofday
76 action => '',
77 cookies => {},
78 headers => {},
79 method => undef,
80 param => {},
81 param_list => [],
82 path_info => '',
83 remote_address => '',
84 remote_user => undef,
85 secure => 0,
86 server_port => undef,
87 start_time => [Time::HiRes::gettimeofday],
88 uploads => {},
89 uri => '',
90 };
91
9215µs bless $this, $class;
93
9411µs if ( ref($initializer) eq 'HASH' ) {
95 while ( my ( $key, $value ) = each %$initializer ) {
96 $this->multi_param(
97 -name => $key,
98 -value => ref($value) eq 'ARRAY' ? [@$value] : [$value]
99 );
100 }
101 }
102 elsif ( ref($initializer) && UNIVERSAL::isa( $initializer, 'GLOB' ) ) {
103 $this->load($initializer);
104 }
10515µs return $this;
106}
107
108=begin TML
109
110---++ ObjectMethod action([$action]) -> $action
111
112
113Gets/Sets action requested (view, edit, save, ...)
114
115=cut
116
117
# spent 21µs within Foswiki::Request::action which was called 4 times, avg 5µs/call: # once (7µs+0s) by Foswiki::Engine::CLI::preparePath at line 98 of /var/www/foswikidev/core/lib/Foswiki/Engine/CLI.pm # once (6µs+0s) by Foswiki::generateHTTPHeaders at line 1089 of /var/www/foswikidev/core/lib/Foswiki.pm # once (5µs+0s) by Foswiki::__ANON__[/var/www/foswikidev/core/lib/Foswiki.pm:312] at line 312 of /var/www/foswikidev/core/lib/Foswiki.pm # once (3µs+0s) by Foswiki::UI::handleRequest at line 196 of /var/www/foswikidev/core/lib/Foswiki/UI.pm
sub action {
11844µs my ( $this, $action ) = @_;
11943µs if ( defined $action ) {
120
121 # Record the very first action set in this request. It will be required
122 # later if a redirect cache overlays this request.
1231900ns $this->{base_action} = $action unless defined $this->{base_action};
12413µs $ENV{FOSWIKI_ACTION} = $this->{action} = $action;
12514µs return $action;
126 }
127 else {
128313µs return $this->{action};
129 }
130
131}
132
133=begin TML
134
135---++ ObjectMethod base_action() -> $action
136
137Get the first action ever set in this request object. This remains
138unchanged even if a request cache is unwrapped on to of this request.
139The idea is that callers can always find out the action that initiated
140the HTTP request. This is required for (for example) checking access
141controls.
142
143=cut
144
145sub base_action {
146 my $this = shift;
147 return defined $this->{base_action}
148 ? $this->{base_action}
149 : $this->action();
150}
151
152=begin TML
153
154---++ ObjectMethod method( [ $method ] ) -> $method
155
156Sets/Gets request method (GET, HEAD, POST).
157
158=cut
159
160
# spent 6µs within Foswiki::Request::method which was called 2 times, avg 3µs/call: # once (3µs+0s) by Foswiki::UI::View::view at line 92 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (2µs+0s) by Foswiki::Engine::CLI::prepareConnection at line 68 of /var/www/foswikidev/core/lib/Foswiki/Engine/CLI.pm
sub method {
16128µs return @_ == 1 ? $_[0]->{method} : ( $_[0]->{method} = $_[1] );
162}
163
164=begin TML
165
166---++ ObjectMethod pathInfo( [ $path ] ) -> $path
167
168Sets/Gets request path info.
169
170Called without parameters returns current pathInfo.
171
172There is a =path_info()= alias for compatibility with CGI.
173
174Note that the string returned is a *URL encoded byte string*
175i.e. it will only contain characters -A-Za-z0-9_.~!*\'();:@&=+$,/?%#[]
176If you intend to analyse it, you will probably have to
177Foswiki::urlDecode it first.
178
179=cut
180
18112µs*path_info = \&pathInfo;
182
183
# spent 25µs within Foswiki::Request::pathInfo which was called 10 times, avg 3µs/call: # 6 times (17µs+0s) by Foswiki::Request::url at line 276, avg 3µs/call # 2 times (3µs+0s) by Foswiki::Plugin::load at line 212 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm, avg 1µs/call # once (4µs+0s) by Foswiki::UI::handleRequest at line 260 of /var/www/foswikidev/core/lib/Foswiki/UI.pm # once (2µs+0s) by Foswiki::new at line 2190 of /var/www/foswikidev/core/lib/Foswiki.pm
sub pathInfo {
1841034µs return @_ == 1 ? $_[0]->{path_info} : ( $_[0]->{path_info} = $_[1] );
185}
186
187=begin TML
188
189---++ ObjectMethod protocol() -> $protocol
190
191Returns 'https' if secure connection. 'http' otherwise.
192
193=cut
194
195# SMELL : review this
196sub protocol {
197 return $_[0]->secure ? 'https' : 'http';
198}
199
200=begin TML
201
202---++ ObjectMethod uri( [$uri] ) -> $uri
203
204Gets/Sets request uri.
205
206=cut
207
208
# spent 3µs within Foswiki::Request::uri which was called: # once (3µs+0s) by Foswiki::generateHTTPHeaders at line 1090 of /var/www/foswikidev/core/lib/Foswiki.pm
sub uri {
20915µs return @_ == 1 ? $_[0]->{uri} : ( $_[0]->{uri} = $_[1] );
210}
211
212=begin TML
213
214---++ ObjectMethod queryString() -> $query_string
215
216Returns query_string part of request uri, if any.
217
218=query_string()= alias provided for compatibility with CGI.
219
220Note that the string returned is a *URL encoded byte string*
221i.e. it will only contain characters -A-Za-z0-9_.~!*\'();:@&=+$,/?%#[]
222If you intend to analyse it, you will probably have to
223Foswiki::urlDecode it first.
224
225=cut
226
2271500ns*query_string = \&queryString;
228
229
# spent 745µs (192+553) within Foswiki::Request::queryString which was called 8 times, avg 93µs/call: # 6 times (153µs+423µs) by Foswiki::Request::url at line 306, avg 96µs/call # once (21µs+73µs) by Foswiki::__ANON__[/var/www/foswikidev/core/lib/Foswiki.pm:289] at line 283 of /var/www/foswikidev/core/lib/Foswiki.pm # once (18µs+57µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1896 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm
sub queryString {
23083µs my $this = shift;
23182µs my @params;
232819µs890µs foreach my $name ( $this->param ) {
# spent 90µs making 8 calls to Foswiki::Request::param, avg 11µs/call
2331623µs16144µs my $key = Foswiki::urlEncode($name);
# spent 144µs making 16 calls to Foswiki::urlEncode, avg 9µs/call
2341629µs16104µs push @params,
# spent 104µs making 16 calls to Foswiki::urlEncode, avg 7µs/call
2351651µs16214µs map { $key . "=" . Foswiki::urlEncode( defined $_ ? $_ : '' ) }
# spent 214µs making 16 calls to Foswiki::Request::param, avg 13µs/call
236 $this->param($name);
237 }
238829µs return join( ';', @params );
239}
240
241=begin TML
242
243---++ ObjectMethod url( [-full => 1,
244 -base => 1,
245 -absolute => 1,
246 -relative => 1,
247 -path => 1,
248 -query => 1] ) -> $url
249
250Returns many url info.
251 * If called without parameters or with -full => 1 returns full url, e.g.
252 http://mysite.net/view
253 * If called with -base => 1 returns base url, e.g. http://foswiki.org
254 * -absolute => 1 returns absolute action path, e.g. /cgi-bin/view
255 * -relative => 1 returns relative action path, e.g. view
256 * -path => 1, -query => 1 also includes path info and query string
257 respectively
258
259Reasonably compatible with CGI corresponding method. Doesn't support
260-rewrite. See Item5914.
261
262=cut
263
264
# spent 1.08ms (171µs+904µs) within Foswiki::Request::url which was called 6 times, avg 179µs/call: # 2 times (74µs+368µs) by Foswiki::Plugins::SubscribePlugin::_getNonce at line 179 of /var/www/foswikidev/core/lib/Foswiki/Plugins/SubscribePlugin.pm, avg 221µs/call # 2 times (44µs+256µs) by Foswiki::Plugin::load at line 212 of /var/www/foswikidev/core/lib/Foswiki/Plugin.pm, avg 150µs/call # once (37µs+164µs) by Foswiki::new at line 2131 of /var/www/foswikidev/core/lib/Foswiki.pm # once (16µs+117µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1895 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm
sub url {
26568µs my ( $this, @p ) = @_;
266
267630µs6151µs my ( $relative, $absolute, $full, $base, $path_info, $query ) = rearrange(
# spent 151µs making 6 calls to CGI::Util::rearrange, avg 25µs/call
268 [
269 qw(RELATIVE ABSOLUTE FULL BASE), [qw(PATH PATH_INFO)],
270 [qw(QUERY_STRING QUERY)],
271 ],
272 @p
273 );
2746800ns my $url;
27565µs $full++ if $base || !( $relative || $absolute );
276615µs617µs my $path = $this->pathInfo;
# spent 17µs making 6 calls to Foswiki::Request::pathInfo, avg 3µs/call
27761µs my $name;
278
279 ## See Foswiki.spec for the difference between ScriptUrlPath and ScriptUrlPaths
280610µs if ( defined $Foswiki::cfg{ScriptUrlPaths}{ $this->{action} } ) {
281
282 # When this is set, it is the complete script path including prefix/suffix.
283 $name = $Foswiki::cfg{ScriptUrlPaths}{ $this->{action} };
284 }
285 else {
286 $name = $Foswiki::cfg{ScriptUrlPath} . '/' . $this->{action};
287
288 # Don't add suffix if no script is used.
289 $name .= $Foswiki::cfg{ScriptSuffix} if $name;
290 }
29166µs $name =~ s(//+)(/)g;
29264µs if ($full) {
293519µs10161µs my $vh = $this->header('X-Forwarded-Host') || $this->header('Host');
# spent 161µs making 10 calls to Foswiki::Request::header, avg 16µs/call
29458µs $url =
295 $vh ? $this->protocol . '://' . $vh : $Foswiki::cfg{DefaultUrlHost};
2965800ns return $url if $base;
29753µs $url .= $name;
298 }
299 elsif ($relative) {
300 ($url) = $name =~ m{([^/]+)$};
301 }
302 elsif ($absolute) {
303 $url = $name;
304 }
30562µs $url .= $path if $path_info && defined $path;
306615µs6576µs my $queryString = $this->queryString();
# spent 576µs making 6 calls to Foswiki::Request::queryString, avg 96µs/call
30763µs $url .= '?' . $queryString if $query && $queryString;
30861µs $url = '' unless defined $url;
309
310623µs return $url;
311}
312
313=begin TML
314
315---++ ObjectMethod secure( [$secure] ) -> $secure
316
317Gets/Sets connection's secure flag.
318
319=cut
320
321sub secure {
322 return @_ == 1 ? $_[0]->{secure} : ( $_[0]->{secure} = $_[1] );
323}
324
325=begin TML
326
327---++ ObjectMethod remoteAddress( [$ip] ) -> $ip
328
329Gets/Sets client IP address.
330
331=remote_addr()= alias for compatibility with CGI.
332
333=cut
334
3351300ns*remote_addr = \&remoteAddress;
336
337
# spent 7µs within Foswiki::Request::remoteAddress which was called 2 times, avg 4µs/call: # once (4µs+0s) by Foswiki::Engine::CLI::prepareConnection at line 67 of /var/www/foswikidev/core/lib/Foswiki/Engine/CLI.pm # once (4µs+0s) by Foswiki::Logger::setCommonFields at line 168 of /var/www/foswikidev/core/lib/Foswiki/Logger.pm
sub remoteAddress {
338210µs return @_ == 1
339 ? $_[0]->{remote_address}
340 : ( $_[0]->{remote_address} = $_[1] );
341}
342
343=begin TML
344
345---++ ObjectMethod remoteUser( [$userName] ) -> $userName
346
347Gets/Sets remote user's name.
348
349=remote_user()= alias for compatibility with CGI.
350
351=cut
352
3531300ns*remote_user = \&remoteUser;
354
355
# spent 8µs within Foswiki::Request::remoteUser which was called 3 times, avg 3µs/call: # once (3µs+0s) by Foswiki::Engine::CLI::prepareHeaders at line 87 of /var/www/foswikidev/core/lib/Foswiki/Engine/CLI.pm # once (3µs+0s) by Foswiki::LoginManager::ApacheLogin::getUser at line 151 of /var/www/foswikidev/core/lib/Foswiki/LoginManager/ApacheLogin.pm # once (2µs+0s) by Foswiki::UI::__ANON__[/var/www/foswikidev/core/lib/Foswiki/UI.pm:376] at line 363 of /var/www/foswikidev/core/lib/Foswiki/UI.pm
sub remoteUser {
356313µs return @_ == 1 ? $_[0]->{remote_user} : ( $_[0]->{remote_user} = $_[1] );
357}
358
359=begin TML
360
361---++ ObjectMethod serverPort( [$userName] ) -> $userName
362
363Gets/Sets server user's name.
364
365=server_port()= alias for compatibility with CGI.
366
367=cut
368
3691400ns*server_port = \&serverPort;
370
371sub serverPort {
372 return @_ == 1 ? $_[0]->{server_port} : ( $_[0]->{server_port} = $_[1] );
373}
374
375=begin TML
376
377---++ ObjectMethod queryParam( [-name => $name, -value => $value |
378 -name => $name, -values => [ $v1, $v2, ... ] |
379 $name, $v1, $v2, ... |
380 name, [ $v1, $v2, ... ]
381 ] ) -> @paramNames | @values | $firstValue
382
383This method is used by engines, during its prepare phase. Should not be used
384anywhere else. Since bodyParam must exist and it has different semantics from
385param method, this one exists for symmetry, and could be modified in the
386future, so it could be possible to get query and body parameters independently.
387
388=cut
389
390sub queryParam {
391 my $this = shift;
392 return if $this->method && $this->method eq 'POST';
393 return $this->param(@_);
394}
395
396=begin TML
397
398---++ ObjectMethod bodyParam( [-name => $name, -value => $value |
399 -name => $name, -values => [ $v1, $v2, ... ] |
400 $name, $v1, $v2, ... |
401 name, [ $v1, $v2, ... ]
402 ] ) -> @paramNames | @values | $firstValue
403
404Adds parameters passed within request body to the object. Should be called
405only by engines. Otherwise use param() method.
406
407=cut
408
409sub bodyParam {
410 my $this = shift;
411 return $this->param(@_);
412}
413
414=begin TML
415
416---++ ObjectMethod param( [-name => $name, -value => $value |
417 -name => $name, -values => [ $v1, $v2, ... ] |
418 $name, $v1, $v2, ... |
419 name, [ $v1, $v2, ... ]
420 ] ) -> @paramNames | @values | $firstValue
421
422 * Called without parameters returns all parameter names
423 * Called only with parameter name or with -name => 'name'
424 * In list context returns all associated values (maybe empty list)
425 * In scalar context returns first value (maybe undef)
426 * Called with name and list of values or with
427 -name => 'name', -value => 'value' or -name => 'name', -values => [ ... ]
428 sets parameter value
429 * Returns parameter values as UTF-8 encoded binary strings
430
431Resonably compatible with CGI.
432
433*NOTE* this method will assert if it is called in a list context. A list
434context might be:
435 * in a list of parameters e.g. =my_function( $query->param( ...=
436 * assigning to a list e.g. =my @l = $query->param(...=
437 * in a loop condition e.g. =foreach ($query->param(...=
438
439The following are *scalar* contexts:
440 * =defined($query->param( ...= is OK
441 * =lc($query->param( ...= is OK
442 * =... if ( $query->param( ...= is OK
443
444In a list context, you should call =multi_param= (fully compatible) to
445retrieve list parameters.
446
447=cut
448
449
# spent 52µs (11+41) within Foswiki::Request::multi_param which was called 3 times, avg 17µs/call: # once (6µs+17µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1891 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (3µs+13µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1892 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (3µs+12µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1893 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm
sub multi_param {
450
45133µs341µs my @list_of_params = param(@_);
# spent 41µs making 3 calls to Foswiki::Request::param, avg 14µs/call
452311µs return @list_of_params;
453}
454
455
# spent 5.15ms (2.29+2.87) within Foswiki::Request::param which was called 225 times, avg 23µs/call: # 50 times (834µs+1.14ms) by Foswiki::getSkin at line 1447 of /var/www/foswikidev/core/lib/Foswiki.pm, avg 39µs/call # 50 times (401µs+360µs) by Foswiki::getSkin at line 1468 of /var/www/foswikidev/core/lib/Foswiki.pm, avg 15µs/call # 40 times (436µs+585µs) by Foswiki::Search::searchWeb at line 349 of /var/www/foswikidev/core/lib/Foswiki/Search.pm, avg 26µs/call # 16 times (126µs+164µs) by Foswiki::If::OP_dollar::evaluate at line 42 of /var/www/foswikidev/core/lib/Foswiki/If/OP_dollar.pm, avg 18µs/call # 16 times (102µs+112µs) by Foswiki::Request::queryString at line 235, avg 13µs/call # 13 times (97µs+127µs) by Foswiki::If::OP_defined::evaluate at line 44 of /var/www/foswikidev/core/lib/Foswiki/If/OP_defined.pm, avg 17µs/call # 8 times (47µs+43µs) by Foswiki::Request::queryString at line 232, avg 11µs/call # 3 times (25µs+32µs) by Foswiki::URLPARAM at line 56 of /var/www/foswikidev/core/lib/Foswiki/Macros/URLPARAM.pm, avg 19µs/call # 3 times (22µs+28µs) by Foswiki::REVINFO at line 24 of /var/www/foswikidev/core/lib/Foswiki/Macros/REVINFO.pm, avg 16µs/call # 3 times (18µs+23µs) by Foswiki::Request::multi_param at line 451, avg 14µs/call # 2 times (26µs+66µs) by Foswiki::Engine::CLI::prepareQueryParameters at line 74 of /var/www/foswikidev/core/lib/Foswiki/Engine/CLI.pm, avg 46µs/call # once (13µs+18µs) by Foswiki::LoginManager::makeLoginManager at line 101 of /var/www/foswikidev/core/lib/Foswiki/LoginManager.pm # once (10µs+12µs) by Foswiki::Plugins::WysiwygPlugin::modifyHeaderHandler at line 369 of /var/www/foswikidev/core/lib/Foswiki/Plugins/WysiwygPlugin.pm # once (9µs+12µs) by Foswiki::Plugins::DirectedGraphPlugin::initPlugin at line 127 of /var/www/foswikidev/core/lib/Foswiki/Plugins/DirectedGraphPlugin.pm # once (8µs+11µs) by Foswiki::UI::View::view at line 73 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (7µs+12µs) by Foswiki::Plugins::TablePlugin::Core::_parseAttributes at line 309 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (8µs+10µs) by Foswiki::UI::View::view at line 281 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (7µs+10µs) by Foswiki::UI::View::view at line 203 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (7µs+10µs) by Foswiki::Plugins::WysiwygPlugin::beforeCommonTagsHandler at line 357 of /var/www/foswikidev/core/lib/Foswiki/Plugins/WysiwygPlugin.pm # once (7µs+10µs) by Foswiki::Plugins::preload at line 139 of /var/www/foswikidev/core/lib/Foswiki/Plugins.pm # once (7µs+9µs) by Foswiki::new at line 2188 of /var/www/foswikidev/core/lib/Foswiki.pm # once (7µs+8µs) by Foswiki::new at line 2192 of /var/www/foswikidev/core/lib/Foswiki.pm # once (8µs+8µs) by Foswiki::UI::View::view at line 324 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (7µs+8µs) by Foswiki::UI::View::view at line 300 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (7µs+7µs) by Foswiki::UI::handleRequest at line 252 of /var/www/foswikidev/core/lib/Foswiki/UI.pm # once (7µs+7µs) by Foswiki::UI::View::view at line 318 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (6µs+7µs) by Foswiki::UI::View::view at line 93 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (6µs+6µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1912 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (5µs+6µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1906 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (5µs+6µs) by Foswiki::UI::View::view at line 94 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (5µs+6µs) by Foswiki::UI::View::view at line 96 of /var/www/foswikidev/core/lib/Foswiki/UI/View.pm # once (5µs+6µs) by Foswiki::Plugins::TablePlugin::Core::handler at line 1916 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm
sub param {
456225280µs my ( $this, @p ) = @_;
457
458225910µs2252.87ms my ( $key, @value ) = rearrange( [ 'NAME', [qw(VALUE VALUES)] ], @p );
# spent 2.87ms making 225 calls to CGI::Util::rearrange, avg 13µs/call
459
460 # param() - just return the list of param names
46122587µs return @{ $this->{param_list} } unless defined $key;
462
463# list context can be dangerous so warn:
464# http://blog.gerv.net/2014.10/new-class-of-vulnerability-in-perl-web-applications
465 if ( DEBUG && wantarray ) {
466 my ( $package, $filename, $line ) = caller;
467 if ( $package ne 'Foswiki::Request' ) {
468 ASSERT( 0,
469"Foswiki::Request::param called in list context from package $package, $filename line $line, declare as scalar, or call multi_param. "
470 );
471 }
472 }
473
47421570µs if ( defined $value[0] ) {
47523µs push @{ $this->{param_list} }, $key
476 unless exists $this->{param}{$key};
47723µs $this->{param}{$key} = ref $value[0] eq 'ARRAY' ? $value[0] : [@value];
478 }
479215474µs if ( defined $this->{param}{$key} ) {
480 return wantarray
481 ? @{ $this->{param}{$key} }
482 : $this->{param}{$key}->[0];
483 }
484 else {
485145508µs return wantarray ? () : undef;
486 }
487}
488
489=begin TML
490
491---++ ObjectMethod cookie($name [, $value, $path, $secure, $expires]) -> $value
492
493 * If called without parameters returns a list of cookie names.
494 * If called only with =$name= parameter returns value of cookie
495 with that name or undef if it doesn't exist.
496 * If called with defined $value and other parameters returns a
497 CGI::Cookie object created with those parameters. Doesn't
498 store this new created cookie within request object. This way
499 for compatibility with CGI.
500
501=cut
502
503
# spent 27µs (14+13) within Foswiki::Request::cookie which was called: # once (14µs+13µs) by Foswiki::Plugins::UpdatesPlugin::initPlugin at line 42 of /var/www/foswikidev/core/lib/Foswiki/Plugins/UpdatesPlugin.pm
sub cookie {
50432µs eval { require CGI::Cookie; 1 } or throw Error::Simple($@);
50511µs my ( $this, @p ) = @_;
50616µs113µs my ( $name, $value, $path, $secure, $expires ) =
# spent 13µs making 1 call to CGI::Util::rearrange
507 rearrange( [ 'NAME', [qw(VALUE VALUES)], 'PATH', 'SECURE', 'EXPIRES' ],
508 @p );
5091400ns unless ( defined $value ) {
5101200ns return keys %{ $this->{cookies} } unless $name;
51115µs return () unless $this->{cookies}{$name};
512 return $this->{cookies}{$name}->value if defined $name && $name ne '';
513 }
514 return unless defined $name && $name ne '';
515 return new CGI::Cookie(
516 -name => $name,
517 -value => $value,
518 -path => $path || '/',
519 -secure => $secure || $this->secure,
520 -expires => $expires || abs( $Foswiki::cfg{Sessions}{ExpireAfter} )
521 );
522}
523
524=begin TML
525
526ObjectMethod cookies( \%cookies ) -> $hashref
527
528Gets/Sets cookies hashref. Keys are cookie names
529and values CGI::Cookie objects.
530
531=cut
532
533sub cookies {
534 return @_ == 1 ? $_[0]->{cookies} : ( $_[0]->{cookies} = $_[1] );
535}
536
537=begin TML
538
539---++ ObjectMethod delete( @paramNames )
540
541Deletes parameters from request.
542
543=Delete()= alias provided for compatibility with CGI
544
545=cut
546
5471300ns*Delete = \&delete;
548
549
# spent 12µs within Foswiki::Request::delete which was called 2 times, avg 6µs/call: # once (7µs+0s) by Foswiki::Plugins::TablePlugin::Core::handler at line 1894 of /var/www/foswikidev/core/lib/Foswiki/Plugins/TablePlugin/Core.pm # once (5µs+0s) by Foswiki::LoginManager::loadSession at line 559 of /var/www/foswikidev/core/lib/Foswiki/LoginManager.pm
sub delete {
55021µs my $this = shift;
551211µs foreach my $p (@_) {
55243µs next unless exists $this->{param}{$p};
553 if ( my $upload = $this->{uploads}{ $this->param($p) } ) {
554 $upload->finish;
555 CORE::delete $this->{uploads}{ $this->param($p) };
556 }
557 CORE::delete $this->{param}{$p};
558 @{ $this->{param_list} } = grep { $_ ne $p } @{ $this->{param_list} };
559 }
560}
561
562=begin TML
563
564---++ ObjectMethod deleteAll()
565
566Deletes all parameter name and value(s).
567
568=delete_all()= alias provided for compatibility with CGI.
569
570=cut
571
5721300ns*delete_all = \&deleteAll;
573
574sub deleteAll {
575 my $this = shift;
576 $this->delete( $this->param() );
577}
578
579=begin TML
580
581---++ ObjectMethod header([-name => $name, -value => $value |
582 -name => $name, -values => [ $v1, $v2, ... ] |
583 $name, $v1, $v2, ... |
584 name, [ $v1, $v2, ... ]
585 ] ) -> @paramNames | @values | $firstValue
586
587Gets/Sets a header field:
588 * Called without parameters returns all header field names
589 * Called only with header field name or with -name => 'name'
590 * In list context returns all associated values (maybe empty list)
591 * In scalar context returns the first value (maybe undef)
592 * Called with name and list of values or with
593 -name => 'name', -value => 'value' or -name => 'name', -values => [ ... ]
594 sets header field value
595
596*Not compatible with CGI*, since CGI correspondent is a
597response write method. CGI scripts obtain headers from %ENV
598or =http= method. %ENV is not available and must be replaced
599by calls to this and other methods of this class. =http= is
600provided for compatibility, but is deprecated. Use this one
601instead.
602
603Calls to CGI =header= method must be replaced by calls to
604Foswiki::Response =header= method.
605
606=cut
607
608
# spent 212µs (117+95) within Foswiki::Request::header which was called 12 times, avg 18µs/call: # 10 times (88µs+72µs) by Foswiki::Request::url at line 293, avg 16µs/call # once (16µs+12µs) by Foswiki::UI::handleRequest at line 237 of /var/www/foswikidev/core/lib/Foswiki/UI.pm # once (13µs+10µs) by Foswiki::Request::userAgent at line 805
sub header {
6091213µs my ( $this, @p ) = @_;
6101235µs1295µs my ( $key, @value ) = rearrange( [ 'NAME', [qw(VALUE VALUES)] ], @p );
# spent 95µs making 12 calls to CGI::Util::rearrange, avg 8µs/call
611
612122µs return keys %{ $this->{headers} } unless $key;
613126µs $key =~ tr/_/-/;
614127µs $key = lc($key);
615
616123µs if ( defined $value[0] ) {
617 $this->{headers}{$key} =
618 ref $value[0] eq 'ARRAY' ? $value[0] : [@value];
619 }
620128µs if ( defined $this->{headers}{$key} ) {
621 return wantarray
622 ? @{ $this->{headers}{$key} }
623 : $this->{headers}{$key}->[0];
624 }
625 else {
6261232µs return wantarray ? () : undef;
627 }
628}
629
630=begin TML
631
632---++ ObjectMethod save( $fh )
633
634Saves object state to filehandle. Object may be loaded later
635passing $fh to new constructor or by calling load().
636
637=cut
638
639sub save {
640 my ( $this, $fh ) = @_;
641 local ( $\, $, ) = ( '', '' );
642 foreach my $name ( $this->param ) {
643 foreach my $value ( $this->param($name) ) {
644 $value = '' unless defined $value;
645 next if $name eq '' && $value eq ''; # Item12371
646 print $fh Foswiki::urlEncode($name), '=',
647 Foswiki::urlEncode($value), "\n";
648 }
649 }
650 print $fh "=\n";
651}
652
653=begin TML
654
655---++ ObjectMethod load( $fh )
656
657Loads object state from filehandle, probably created with
658a previous save().
659
660=cut
661
662sub load {
663 my ( $this, $file ) = @_;
664 my %param = ();
665 my @plist = ();
666 local $/ = "\n";
667 while (<$file>) {
668 chomp;
669 last if /^=$/;
670 my ( $key, $value ) =
671 map { defined $_ ? Foswiki::urlDecode($_) : $_ } split /=/;
672
673 # Item12956: Split returns only a single entry in array for null values.
674 # save sets null values to '', so load needs to restore '', not undef
675 $value = '' unless defined $value;
676 if ( exists $param{$key} ) {
677 push @{ $param{$key} }, $value;
678 }
679 else {
680 push @plist, $key;
681 $param{$key} = [$value];
682 }
683 }
684 foreach my $key (@plist) {
685 $this->multi_param( -name => $key, -value => $param{$key} );
686 }
687}
688
689=begin TML
690
691---++ ObjectMethod upload( $name ) -> $handle
692
693Called with file name parameter returns an open filehandle
694to uploaded file.
695
696=cut
697
698sub upload {
699 my ( $this, $name ) = @_;
700 my $upload = $this->{uploads}{ $this->param($name) };
701 return defined $upload ? $upload->handle : undef;
702}
703
704=begin TML
705
706---++ ObjectMethod uploadInfo( $fname ) -> $headers
707
708Returns a hashref to information about uploaded
709files as sent by browser.
710
711=cut
712
713sub uploadInfo {
714 return $_[0]->{uploads}{ $_[1] }->uploadInfo;
715}
716
717=begin TML
718
719---++ ObjectMethod tmpFileName( $fname ) -> $tmpFileName
720
721Returns the name of temporarly created file to store uploaded $fname.
722
723$fname may be obtained by calling =param()= with form field name.
724
725=cut
726
727sub tmpFileName {
728 my ( $this, $fname ) = @_;
729 return $this->{uploads}{$fname}
730 ? $this->{uploads}{$fname}->tmpFileName
731 : undef;
732}
733
734=begin TML
735
736---++ ObjectMethod uploads( [ \%uploads ] ) -> $hashref
737
738Gets/Sets request uploads field. Keys are uploaded file names,
739as sent by browser, and values are Foswiki::Request::Upload objects.
740
741=cut
742
743sub uploads {
744 return @_ == 1 ? $_[0]->{uploads} : ( $_[0]->{uploads} = $_[1] );
745}
746
747# ======== possible accessors =======
748# auth_type
749# content_length
750# content_type
751
752=begin TML
753
754---++ ObjectMethod http( [$header] ) -> $value DEPRECATED
755
756Called without parameters returns a list of all available header filed names.
757
758Given a field name returns value associated.
759
760http('HTTP_USER_AGENT'); http('User-Agent') and http('User_Agent')
761are equivalent.
762
763Please, use =header()= instead. Present only for compatibility with CGI.
764
765=cut
766
767sub http {
768 my ( $this, $p ) = @_;
769 if ( defined $p ) {
770 $p =~ s/^https?[_-]//i;
771 return $this->header($p);
772 }
773 return $this->header();
774}
775
776=begin TML
777
778---++ ObjectMethod https( [$name] ) -> $value || $secure DEPRECATED
779
780Similar to =http()= method above. Called with no parameters returns
781secure flag.
782
783Please, use =header()= and =secure()= instead.
784Present only for compatibility with CGI.
785
786=cut
787
788sub https {
789 my ( $this, $p ) = @_;
790 return !defined $p || $p =~ m/^https$/i ? $this->secure : $this->http($p);
791}
792
793=begin TML
794
795---++ ObjectMethod userAgent() -> $userAgent;
796
797Convenience method to get User-Agent string.
798
799=user_agent()= alias provided for compatibility with CGI.
800
801=cut
802
8031400ns*user_agent = \&userAgent;
804
80515µs123µs
# spent 28µs (6+23) within Foswiki::Request::userAgent which was called: # once (6µs+23µs) by Foswiki::Logger::setCommonFields at line 152 of /var/www/foswikidev/core/lib/Foswiki/Logger.pm
sub userAgent { shift->header('User-Agent') }
# spent 23µs making 1 call to Foswiki::Request::header
806
807=begin TML
808
809---++ ObjectMethod referer()
810
811Convenience method to get Referer uri.
812
813=cut
814
815sub referer { shift->header('Referer') }
816
81717µs1;
818__END__