Filename | /var/www/foswikidev/core/lib/Foswiki/Request.pm |
Statements | Executed 1627 statements in 5.54ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
225 | 32 | 15 | 2.29ms | 5.15ms | param | Foswiki::Request::
1 | 1 | 1 | 2.03ms | 3.06ms | BEGIN@39 | Foswiki::Request::
1 | 1 | 1 | 627µs | 5.04ms | BEGIN@37 | Foswiki::Request::
8 | 3 | 3 | 192µs | 745µs | queryString | Foswiki::Request::
6 | 4 | 4 | 171µs | 1.08ms | url | Foswiki::Request::
12 | 3 | 2 | 117µs | 212µs | header | Foswiki::Request::
1 | 1 | 1 | 26µs | 38µs | new | Foswiki::Request::
10 | 4 | 4 | 25µs | 25µs | pathInfo | Foswiki::Request::
4 | 4 | 3 | 21µs | 21µs | action | Foswiki::Request::
1 | 1 | 1 | 21µs | 32µs | getTime | Foswiki::Request::
1 | 1 | 1 | 14µs | 27µs | cookie | Foswiki::Request::
1 | 1 | 1 | 14µs | 28µs | BEGIN@29 | Foswiki::Request::
2 | 2 | 2 | 12µs | 12µs | delete | Foswiki::Request::
1 | 1 | 1 | 12µs | 29µs | BEGIN@38 | Foswiki::Request::
3 | 3 | 1 | 11µs | 52µs | multi_param | Foswiki::Request::
1 | 1 | 1 | 9µs | 34µs | BEGIN@35 | Foswiki::Request::
1 | 1 | 1 | 9µs | 14µs | BEGIN@30 | Foswiki::Request::
3 | 3 | 3 | 8µs | 8µs | remoteUser | Foswiki::Request::
2 | 2 | 2 | 7µs | 7µs | remoteAddress | Foswiki::Request::
2 | 2 | 2 | 6µs | 6µs | method | Foswiki::Request::
1 | 1 | 1 | 6µs | 28µs | userAgent | Foswiki::Request::
1 | 1 | 1 | 5µs | 5µs | BEGIN@41 | Foswiki::Request::
1 | 1 | 1 | 4µs | 4µs | BEGIN@36 | Foswiki::Request::
1 | 1 | 1 | 4µs | 4µs | BEGIN@32 | Foswiki::Request::
1 | 1 | 1 | 3µs | 3µs | uri | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | base_action | Foswiki::Request::
0 | 0 | 0 | 0s | 0s | bodyParam | 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 | 28µs | 2 | 42µ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 # spent 28µs making 1 call to Foswiki::Request::BEGIN@29
# spent 14µs making 1 call to strict::import |
30 | 2 | 24µs | 2 | 18µ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 # spent 14µs making 1 call to Foswiki::Request::BEGIN@30
# spent 5µs making 1 call to warnings::import |
31 | |||||
32 | 2 | 33µ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 | 7µs | our @ISA = ('CGI'); | ||
34 | |||||
35 | 2 | 25µs | 2 | 59µ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 # spent 34µs making 1 call to Foswiki::Request::BEGIN@35
# spent 25µs making 1 call to Exporter::import |
36 | 2 | 19µ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 | 168µs | 1 | 5.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 # spent 5.04ms making 1 call to Foswiki::Request::BEGIN@37 |
38 | 2 | 28µs | 2 | 45µ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 # spent 29µs making 1 call to Foswiki::Request::BEGIN@38
# spent 17µs making 1 call to Exporter::import |
39 | 2 | 129µs | 1 | 3.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 # 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 | ||||
42 | 1 | 5µs | if ( $Foswiki::cfg{UseLocale} ) { | ||
43 | require locale; | ||||
44 | import locale(); | ||||
45 | } | ||||
46 | 1 | 2.10ms | 1 | 5µ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 | ||||
49 | 1 | 2µs | my $this = shift; | ||
50 | 1 | 10µs | 1 | 3µs | my $endTime = [Time::HiRes::gettimeofday]; # spent 3µs making 1 call to Time::HiRes::gettimeofday |
51 | 1 | 6µs | 1 | 8µs | my $timeDiff = Time::HiRes::tv_interval( $this->{start_time}, $endTime ); # spent 8µs making 1 call to Time::HiRes::tv_interval |
52 | 1 | 5µs | return $timeDiff; | ||
53 | } | ||||
54 | |||||
55 | =begin TML | ||||
56 | |||||
57 | ---++ ClassMethod new([$initializer]) | ||||
58 | |||||
59 | Constructs 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 | ||||
69 | 1 | 1µs | my ( $proto, $initializer ) = @_; | ||
70 | |||||
71 | 1 | 200ns | my $this; | ||
72 | |||||
73 | 1 | 900ns | my $class = ref($proto) || $proto; | ||
74 | |||||
75 | 1 | 26µs | 1 | 12µ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 | |||||
92 | 1 | 5µs | bless $this, $class; | ||
93 | |||||
94 | 1 | 1µ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 | } | ||||
105 | 1 | 5µs | return $this; | ||
106 | } | ||||
107 | |||||
108 | =begin TML | ||||
109 | |||||
110 | ---++ ObjectMethod action([$action]) -> $action | ||||
111 | |||||
112 | |||||
113 | Gets/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 | ||||
118 | 4 | 4µs | my ( $this, $action ) = @_; | ||
119 | 4 | 3µ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. | ||||
123 | 1 | 900ns | $this->{base_action} = $action unless defined $this->{base_action}; | ||
124 | 1 | 3µs | $ENV{FOSWIKI_ACTION} = $this->{action} = $action; | ||
125 | 1 | 4µs | return $action; | ||
126 | } | ||||
127 | else { | ||||
128 | 3 | 13µs | return $this->{action}; | ||
129 | } | ||||
130 | |||||
131 | } | ||||
132 | |||||
133 | =begin TML | ||||
134 | |||||
135 | ---++ ObjectMethod base_action() -> $action | ||||
136 | |||||
137 | Get the first action ever set in this request object. This remains | ||||
138 | unchanged even if a request cache is unwrapped on to of this request. | ||||
139 | The idea is that callers can always find out the action that initiated | ||||
140 | the HTTP request. This is required for (for example) checking access | ||||
141 | controls. | ||||
142 | |||||
143 | =cut | ||||
144 | |||||
145 | sub 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 | |||||
156 | Sets/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 | ||||
161 | 2 | 8µs | return @_ == 1 ? $_[0]->{method} : ( $_[0]->{method} = $_[1] ); | ||
162 | } | ||||
163 | |||||
164 | =begin TML | ||||
165 | |||||
166 | ---++ ObjectMethod pathInfo( [ $path ] ) -> $path | ||||
167 | |||||
168 | Sets/Gets request path info. | ||||
169 | |||||
170 | Called without parameters returns current pathInfo. | ||||
171 | |||||
172 | There is a =path_info()= alias for compatibility with CGI. | ||||
173 | |||||
174 | Note that the string returned is a *URL encoded byte string* | ||||
175 | i.e. it will only contain characters -A-Za-z0-9_.~!*\'();:@&=+$,/?%#[] | ||||
176 | If you intend to analyse it, you will probably have to | ||||
177 | Foswiki::urlDecode it first. | ||||
178 | |||||
179 | =cut | ||||
180 | |||||
181 | 1 | 2µ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 | ||||
184 | 10 | 34µs | return @_ == 1 ? $_[0]->{path_info} : ( $_[0]->{path_info} = $_[1] ); | ||
185 | } | ||||
186 | |||||
187 | =begin TML | ||||
188 | |||||
189 | ---++ ObjectMethod protocol() -> $protocol | ||||
190 | |||||
191 | Returns 'https' if secure connection. 'http' otherwise. | ||||
192 | |||||
193 | =cut | ||||
194 | |||||
195 | # SMELL : review this | ||||
196 | sub protocol { | ||||
197 | return $_[0]->secure ? 'https' : 'http'; | ||||
198 | } | ||||
199 | |||||
200 | =begin TML | ||||
201 | |||||
202 | ---++ ObjectMethod uri( [$uri] ) -> $uri | ||||
203 | |||||
204 | Gets/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 | ||||
209 | 1 | 5µs | return @_ == 1 ? $_[0]->{uri} : ( $_[0]->{uri} = $_[1] ); | ||
210 | } | ||||
211 | |||||
212 | =begin TML | ||||
213 | |||||
214 | ---++ ObjectMethod queryString() -> $query_string | ||||
215 | |||||
216 | Returns query_string part of request uri, if any. | ||||
217 | |||||
218 | =query_string()= alias provided for compatibility with CGI. | ||||
219 | |||||
220 | Note that the string returned is a *URL encoded byte string* | ||||
221 | i.e. it will only contain characters -A-Za-z0-9_.~!*\'();:@&=+$,/?%#[] | ||||
222 | If you intend to analyse it, you will probably have to | ||||
223 | Foswiki::urlDecode it first. | ||||
224 | |||||
225 | =cut | ||||
226 | |||||
227 | 1 | 500ns | *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 | ||||
230 | 8 | 3µs | my $this = shift; | ||
231 | 8 | 2µs | my @params; | ||
232 | 8 | 19µs | 8 | 90µs | foreach my $name ( $this->param ) { # spent 90µs making 8 calls to Foswiki::Request::param, avg 11µs/call |
233 | 16 | 23µs | 16 | 144µs | my $key = Foswiki::urlEncode($name); # spent 144µs making 16 calls to Foswiki::urlEncode, avg 9µs/call |
234 | 16 | 29µs | 16 | 104µs | push @params, # spent 104µs making 16 calls to Foswiki::urlEncode, avg 7µs/call |
235 | 16 | 51µs | 16 | 214µ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 | } | ||||
238 | 8 | 29µ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 | |||||
250 | Returns 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 | |||||
259 | Reasonably 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 | ||||
265 | 6 | 8µs | my ( $this, @p ) = @_; | ||
266 | |||||
267 | 6 | 30µs | 6 | 151µ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 | ); | ||||
274 | 6 | 800ns | my $url; | ||
275 | 6 | 5µs | $full++ if $base || !( $relative || $absolute ); | ||
276 | 6 | 15µs | 6 | 17µs | my $path = $this->pathInfo; # spent 17µs making 6 calls to Foswiki::Request::pathInfo, avg 3µs/call |
277 | 6 | 1µs | my $name; | ||
278 | |||||
279 | ## See Foswiki.spec for the difference between ScriptUrlPath and ScriptUrlPaths | ||||
280 | 6 | 10µ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 | } | ||||
291 | 6 | 6µs | $name =~ s(//+)(/)g; | ||
292 | 6 | 4µs | if ($full) { | ||
293 | 5 | 19µs | 10 | 161µ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 |
294 | 5 | 8µs | $url = | ||
295 | $vh ? $this->protocol . '://' . $vh : $Foswiki::cfg{DefaultUrlHost}; | ||||
296 | 5 | 800ns | return $url if $base; | ||
297 | 5 | 3µs | $url .= $name; | ||
298 | } | ||||
299 | elsif ($relative) { | ||||
300 | ($url) = $name =~ m{([^/]+)$}; | ||||
301 | } | ||||
302 | elsif ($absolute) { | ||||
303 | $url = $name; | ||||
304 | } | ||||
305 | 6 | 2µs | $url .= $path if $path_info && defined $path; | ||
306 | 6 | 15µs | 6 | 576µs | my $queryString = $this->queryString(); # spent 576µs making 6 calls to Foswiki::Request::queryString, avg 96µs/call |
307 | 6 | 3µs | $url .= '?' . $queryString if $query && $queryString; | ||
308 | 6 | 1µs | $url = '' unless defined $url; | ||
309 | |||||
310 | 6 | 23µs | return $url; | ||
311 | } | ||||
312 | |||||
313 | =begin TML | ||||
314 | |||||
315 | ---++ ObjectMethod secure( [$secure] ) -> $secure | ||||
316 | |||||
317 | Gets/Sets connection's secure flag. | ||||
318 | |||||
319 | =cut | ||||
320 | |||||
321 | sub secure { | ||||
322 | return @_ == 1 ? $_[0]->{secure} : ( $_[0]->{secure} = $_[1] ); | ||||
323 | } | ||||
324 | |||||
325 | =begin TML | ||||
326 | |||||
327 | ---++ ObjectMethod remoteAddress( [$ip] ) -> $ip | ||||
328 | |||||
329 | Gets/Sets client IP address. | ||||
330 | |||||
331 | =remote_addr()= alias for compatibility with CGI. | ||||
332 | |||||
333 | =cut | ||||
334 | |||||
335 | 1 | 300ns | *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 | ||||
338 | 2 | 10µs | return @_ == 1 | ||
339 | ? $_[0]->{remote_address} | ||||
340 | : ( $_[0]->{remote_address} = $_[1] ); | ||||
341 | } | ||||
342 | |||||
343 | =begin TML | ||||
344 | |||||
345 | ---++ ObjectMethod remoteUser( [$userName] ) -> $userName | ||||
346 | |||||
347 | Gets/Sets remote user's name. | ||||
348 | |||||
349 | =remote_user()= alias for compatibility with CGI. | ||||
350 | |||||
351 | =cut | ||||
352 | |||||
353 | 1 | 300ns | *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 | ||||
356 | 3 | 13µs | return @_ == 1 ? $_[0]->{remote_user} : ( $_[0]->{remote_user} = $_[1] ); | ||
357 | } | ||||
358 | |||||
359 | =begin TML | ||||
360 | |||||
361 | ---++ ObjectMethod serverPort( [$userName] ) -> $userName | ||||
362 | |||||
363 | Gets/Sets server user's name. | ||||
364 | |||||
365 | =server_port()= alias for compatibility with CGI. | ||||
366 | |||||
367 | =cut | ||||
368 | |||||
369 | 1 | 400ns | *server_port = \&serverPort; | ||
370 | |||||
371 | sub 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 | |||||
383 | This method is used by engines, during its prepare phase. Should not be used | ||||
384 | anywhere else. Since bodyParam must exist and it has different semantics from | ||||
385 | param method, this one exists for symmetry, and could be modified in the | ||||
386 | future, so it could be possible to get query and body parameters independently. | ||||
387 | |||||
388 | =cut | ||||
389 | |||||
390 | sub 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 | |||||
404 | Adds parameters passed within request body to the object. Should be called | ||||
405 | only by engines. Otherwise use param() method. | ||||
406 | |||||
407 | =cut | ||||
408 | |||||
409 | sub 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 | |||||
431 | Resonably compatible with CGI. | ||||
432 | |||||
433 | *NOTE* this method will assert if it is called in a list context. A list | ||||
434 | context 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 | |||||
439 | The following are *scalar* contexts: | ||||
440 | * =defined($query->param( ...= is OK | ||||
441 | * =lc($query->param( ...= is OK | ||||
442 | * =... if ( $query->param( ...= is OK | ||||
443 | |||||
444 | In a list context, you should call =multi_param= (fully compatible) to | ||||
445 | retrieve 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 | ||||
450 | |||||
451 | 3 | 3µs | 3 | 41µs | my @list_of_params = param(@_); # spent 41µs making 3 calls to Foswiki::Request::param, avg 14µs/call |
452 | 3 | 11µ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 | ||||
456 | 225 | 280µs | my ( $this, @p ) = @_; | ||
457 | |||||
458 | 225 | 910µs | 225 | 2.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 | ||||
461 | 225 | 87µ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 | |||||
474 | 215 | 70µs | if ( defined $value[0] ) { | ||
475 | 2 | 3µs | push @{ $this->{param_list} }, $key | ||
476 | unless exists $this->{param}{$key}; | ||||
477 | 2 | 3µs | $this->{param}{$key} = ref $value[0] eq 'ARRAY' ? $value[0] : [@value]; | ||
478 | } | ||||
479 | 215 | 474µs | if ( defined $this->{param}{$key} ) { | ||
480 | return wantarray | ||||
481 | ? @{ $this->{param}{$key} } | ||||
482 | : $this->{param}{$key}->[0]; | ||||
483 | } | ||||
484 | else { | ||||
485 | 145 | 508µ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 | ||||
504 | 3 | 2µs | eval { require CGI::Cookie; 1 } or throw Error::Simple($@); | ||
505 | 1 | 1µs | my ( $this, @p ) = @_; | ||
506 | 1 | 6µs | 1 | 13µ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 ); | ||||
509 | 1 | 400ns | unless ( defined $value ) { | ||
510 | 1 | 200ns | return keys %{ $this->{cookies} } unless $name; | ||
511 | 1 | 5µ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 | |||||
526 | ObjectMethod cookies( \%cookies ) -> $hashref | ||||
527 | |||||
528 | Gets/Sets cookies hashref. Keys are cookie names | ||||
529 | and values CGI::Cookie objects. | ||||
530 | |||||
531 | =cut | ||||
532 | |||||
533 | sub cookies { | ||||
534 | return @_ == 1 ? $_[0]->{cookies} : ( $_[0]->{cookies} = $_[1] ); | ||||
535 | } | ||||
536 | |||||
537 | =begin TML | ||||
538 | |||||
539 | ---++ ObjectMethod delete( @paramNames ) | ||||
540 | |||||
541 | Deletes parameters from request. | ||||
542 | |||||
543 | =Delete()= alias provided for compatibility with CGI | ||||
544 | |||||
545 | =cut | ||||
546 | |||||
547 | 1 | 300ns | *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 | ||||
550 | 2 | 1µs | my $this = shift; | ||
551 | 2 | 11µs | foreach my $p (@_) { | ||
552 | 4 | 3µ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 | |||||
566 | Deletes all parameter name and value(s). | ||||
567 | |||||
568 | =delete_all()= alias provided for compatibility with CGI. | ||||
569 | |||||
570 | =cut | ||||
571 | |||||
572 | 1 | 300ns | *delete_all = \&deleteAll; | ||
573 | |||||
574 | sub 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 | |||||
587 | Gets/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 | ||||
597 | response write method. CGI scripts obtain headers from %ENV | ||||
598 | or =http= method. %ENV is not available and must be replaced | ||||
599 | by calls to this and other methods of this class. =http= is | ||||
600 | provided for compatibility, but is deprecated. Use this one | ||||
601 | instead. | ||||
602 | |||||
603 | Calls to CGI =header= method must be replaced by calls to | ||||
604 | Foswiki::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 | ||||
609 | 12 | 13µs | my ( $this, @p ) = @_; | ||
610 | 12 | 35µs | 12 | 95µ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 | |||||
612 | 12 | 2µs | return keys %{ $this->{headers} } unless $key; | ||
613 | 12 | 6µs | $key =~ tr/_/-/; | ||
614 | 12 | 7µs | $key = lc($key); | ||
615 | |||||
616 | 12 | 3µs | if ( defined $value[0] ) { | ||
617 | $this->{headers}{$key} = | ||||
618 | ref $value[0] eq 'ARRAY' ? $value[0] : [@value]; | ||||
619 | } | ||||
620 | 12 | 8µs | if ( defined $this->{headers}{$key} ) { | ||
621 | return wantarray | ||||
622 | ? @{ $this->{headers}{$key} } | ||||
623 | : $this->{headers}{$key}->[0]; | ||||
624 | } | ||||
625 | else { | ||||
626 | 12 | 32µs | return wantarray ? () : undef; | ||
627 | } | ||||
628 | } | ||||
629 | |||||
630 | =begin TML | ||||
631 | |||||
632 | ---++ ObjectMethod save( $fh ) | ||||
633 | |||||
634 | Saves object state to filehandle. Object may be loaded later | ||||
635 | passing $fh to new constructor or by calling load(). | ||||
636 | |||||
637 | =cut | ||||
638 | |||||
639 | sub 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 | |||||
657 | Loads object state from filehandle, probably created with | ||||
658 | a previous save(). | ||||
659 | |||||
660 | =cut | ||||
661 | |||||
662 | sub 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 | |||||
693 | Called with file name parameter returns an open filehandle | ||||
694 | to uploaded file. | ||||
695 | |||||
696 | =cut | ||||
697 | |||||
698 | sub 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 | |||||
708 | Returns a hashref to information about uploaded | ||||
709 | files as sent by browser. | ||||
710 | |||||
711 | =cut | ||||
712 | |||||
713 | sub uploadInfo { | ||||
714 | return $_[0]->{uploads}{ $_[1] }->uploadInfo; | ||||
715 | } | ||||
716 | |||||
717 | =begin TML | ||||
718 | |||||
719 | ---++ ObjectMethod tmpFileName( $fname ) -> $tmpFileName | ||||
720 | |||||
721 | Returns 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 | |||||
727 | sub 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 | |||||
738 | Gets/Sets request uploads field. Keys are uploaded file names, | ||||
739 | as sent by browser, and values are Foswiki::Request::Upload objects. | ||||
740 | |||||
741 | =cut | ||||
742 | |||||
743 | sub 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 | |||||
756 | Called without parameters returns a list of all available header filed names. | ||||
757 | |||||
758 | Given a field name returns value associated. | ||||
759 | |||||
760 | http('HTTP_USER_AGENT'); http('User-Agent') and http('User_Agent') | ||||
761 | are equivalent. | ||||
762 | |||||
763 | Please, use =header()= instead. Present only for compatibility with CGI. | ||||
764 | |||||
765 | =cut | ||||
766 | |||||
767 | sub 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 | |||||
780 | Similar to =http()= method above. Called with no parameters returns | ||||
781 | secure flag. | ||||
782 | |||||
783 | Please, use =header()= and =secure()= instead. | ||||
784 | Present only for compatibility with CGI. | ||||
785 | |||||
786 | =cut | ||||
787 | |||||
788 | sub 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 | |||||
797 | Convenience method to get User-Agent string. | ||||
798 | |||||
799 | =user_agent()= alias provided for compatibility with CGI. | ||||
800 | |||||
801 | =cut | ||||
802 | |||||
803 | 1 | 400ns | *user_agent = \&userAgent; | ||
804 | |||||
805 | 1 | 5µs | 1 | 23µ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 # spent 23µs making 1 call to Foswiki::Request::header |
806 | |||||
807 | =begin TML | ||||
808 | |||||
809 | ---++ ObjectMethod referer() | ||||
810 | |||||
811 | Convenience method to get Referer uri. | ||||
812 | |||||
813 | =cut | ||||
814 | |||||
815 | sub referer { shift->header('Referer') } | ||||
816 | |||||
817 | 1 | 7µs | 1; | ||
818 | __END__ |