~ubuntu-branches/ubuntu/edgy/libapache2-mod-perl2/edgy

« back to all changes in this revision

Viewing changes to docs/api/Apache/RequestUtil.pod

  • Committer: Bazaar Package Importer
  • Author(s): Andres Salomon
  • Date: 2005-08-12 01:40:38 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050812014038-gjigefs55pqx4qc8
Tags: 2.0.1-3
Grr.  Really include perl.conf file; it got lost due to diff not
wanting to add an empty file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
=head1 NAME
2
 
 
3
 
Apache::RequestUtil - Perl API for Apache request record utils
4
 
 
5
 
 
6
 
 
7
 
 
8
 
=head1 Synopsis
9
 
 
10
 
  use Apache::RequestUtil ();
11
 
  
12
 
  # directory level PerlOptions flags lookup
13
 
  $r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');
14
 
 
15
 
META: to be completed
16
 
 
17
 
 
18
 
 
19
 
 
20
 
=head1 Description
21
 
 
22
 
META: to be completed
23
 
 
24
 
 
25
 
 
26
 
=head1 Class methods API
27
 
 
28
 
=head2 C<request>
29
 
 
30
 
Retrieve the
31
 
(C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>) object
32
 
for the current request.
33
 
 
34
 
  $r = Apache->request;
35
 
 
36
 
=over 4
37
 
 
38
 
=item obj: C<Apache> (class name)
39
 
 
40
 
The Apache class
41
 
 
42
 
=item ret: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
43
 
 
44
 
=item since: 1.99_10
45
 
 
46
 
=back
47
 
 
48
 
This method is only available if C<L<PerlOptions
49
 
+GlobalRequest|docs::2.0::user::config::config/C_GlobalRequest_>> is
50
 
in effect.
51
 
 
52
 
 
53
 
=head1 Methods API
54
 
 
55
 
 
56
 
 
57
 
=head2 C<default_type>
58
 
 
59
 
META: Autogenerated - needs to be reviewed/completed
60
 
 
61
 
Retrieve the value of the DefaultType directive, or text/plain if not set
62
 
 
63
 
  $ret = $r->default_type();
64
 
 
65
 
=over 4
66
 
 
67
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
68
 
 
69
 
The current request
70
 
 
71
 
=item ret: C<$ret> (string)
72
 
 
73
 
The default type
74
 
 
75
 
=back
76
 
 
77
 
 
78
 
 
79
 
 
80
 
 
81
 
=head2 C<document_root>
82
 
 
83
 
META: Autogenerated - needs to be reviewed/completed
84
 
 
85
 
Retrieve the document root for this server
86
 
 
87
 
  $ret = $r->document_root();
88
 
 
89
 
=over 4
90
 
 
91
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
92
 
 
93
 
The current request
94
 
 
95
 
=item ret: C<$ret> (string)
96
 
 
97
 
The document root
98
 
 
99
 
=back
100
 
 
101
 
 
102
 
 
103
 
 
104
 
 
105
 
=head2 C<get_limit_req_body>
106
 
 
107
 
META: Autogenerated - needs to be reviewed/completed
108
 
 
109
 
Return the limit on bytes in request msg body
110
 
 
111
 
  $ret = $r->get_limit_req_body();
112
 
 
113
 
=over 4
114
 
 
115
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
116
 
 
117
 
The current request
118
 
 
119
 
=item ret: C<$ret> (integer)
120
 
 
121
 
the maximum number of bytes in the request msg body
122
 
 
123
 
=back
124
 
 
125
 
 
126
 
 
127
 
 
128
 
 
129
 
=head2 C<get_server_name>
130
 
 
131
 
META: Autogenerated - needs to be reviewed/completed
132
 
 
133
 
Get the current server name from the request
134
 
 
135
 
  $ret = $r->get_server_name();
136
 
 
137
 
=over 4
138
 
 
139
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
140
 
 
141
 
The current request
142
 
 
143
 
=item ret: C<$ret> (string)
144
 
 
145
 
the server name
146
 
 
147
 
=back
148
 
 
149
 
 
150
 
 
151
 
 
152
 
 
153
 
=head2 C<get_server_port>
154
 
 
155
 
META: Autogenerated - needs to be reviewed/completed
156
 
 
157
 
Get the current server port
158
 
 
159
 
  $ret = $r->get_server_port();
160
 
 
161
 
=over 4
162
 
 
163
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
164
 
 
165
 
 
166
 
 
167
 
=item ret: C<$ret> (integer)
168
 
 
169
 
The server's port
170
 
 
171
 
=back
172
 
 
173
 
 
174
 
 
175
 
 
176
 
 
177
 
=head2 C<get_status_line>
178
 
 
179
 
META: Autogenerated - needs to be reviewed/completed
180
 
 
181
 
Return the Status-Line for a given status code (excluding the
182
 
HTTP-Version field). If an invalid or unknown status code is
183
 
passed, "500 Internal Server Error" will be returned.
184
 
 
185
 
  $ret = get_status_line($status);
186
 
 
187
 
=over 4
188
 
 
189
 
=item obj: C<$status> (integer)
190
 
 
191
 
The HTTP status code
192
 
 
193
 
=item ret: C<$ret> (string)
194
 
 
195
 
The Status-Line
196
 
 
197
 
=back
198
 
 
199
 
 
200
 
 
201
 
 
202
 
 
203
 
=head2 C<is_initial_req>
204
 
 
205
 
META: Autogenerated - needs to be reviewed/completed
206
 
 
207
 
Determine if the current request is the main request or a sub requests
208
 
 
209
 
  $ret = $r->is_initial_req();
210
 
 
211
 
=over 4
212
 
 
213
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
214
 
 
215
 
The current request
216
 
 
217
 
=item ret: C<$ret> (integer)
218
 
 
219
 
 
220
 
 
221
 
=back
222
 
 
223
 
 
224
 
 
225
 
 
226
 
 
227
 
=head2 C<method_register>
228
 
 
229
 
META: Autogenerated - needs to be reviewed/completed
230
 
 
231
 
Register a new request method, and return the offset that will be
232
 
associated with that method.
233
 
 
234
 
  $ret = $p->method_register($methname);
235
 
 
236
 
=over 4
237
 
 
238
 
=item obj: C<$p> (C<L<APR::Pool|docs::2.0::api::APR::Pool>>)
239
 
 
240
 
The pool to create registered method numbers from.
241
 
 
242
 
=item arg1: C<$methname> (string)
243
 
 
244
 
The name of the new method to register.
245
 
 
246
 
=item ret: C<$ret> (integer)
247
 
 
248
 
Ab int value representing an offset into a bitmask.
249
 
 
250
 
=back
251
 
 
252
 
 
253
 
 
254
 
 
255
 
 
256
 
=head2 C<add_config>
257
 
 
258
 
META: Autogenerated - needs to be reviewed/completed
259
 
 
260
 
 
261
 
 
262
 
  $ret = $r->add_config($lines, $path, $override);
263
 
 
264
 
=over 4
265
 
 
266
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
267
 
 
268
 
=item arg1: C<$lines> (ARRAY ref)
269
 
 
270
 
=item opt arg3: C<$path> (scalar)
271
 
 
272
 
=item opt arg4: C<$override> (string)
273
 
 
274
 
=item ret: C<$ret> (string)
275
 
 
276
 
=back
277
 
 
278
 
See also:
279
 
C<L<$s-E<gt>add_config|docs::2.0::api::Apache::ServerUtil/C_add_config_>>
280
 
 
281
 
 
282
 
=head2 C<location>
283
 
 
284
 
META: Autogenerated - needs to be reviewed/completed
285
 
 
286
 
 
287
 
 
288
 
  $location = $r->location($location);
289
 
 
290
 
=over 4
291
 
 
292
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
293
 
 
294
 
=item opt arg2: C<$location> (string)
295
 
 
296
 
=item ret: C<$location> (integer)
297
 
 
298
 
=back
299
 
 
300
 
 
301
 
 
302
 
 
303
 
=head2 C<location_merge>
304
 
 
305
 
META: Autogenerated - needs to be reviewed/completed
306
 
 
307
 
 
308
 
 
309
 
  $ret = $r->location_merge($location);
310
 
 
311
 
=over 4
312
 
 
313
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
314
 
 
315
 
=item arg1: C<$location> (string)
316
 
 
317
 
=item ret: C<$ret> (integer)
318
 
 
319
 
=back
320
 
 
321
 
 
322
 
 
323
 
=head2 C<pnotes>
324
 
 
325
 
META: Autogenerated - needs to be reviewed/completed
326
 
 
327
 
Notes from one module to another
328
 
 
329
 
  $pnotes = $r->pnotes();
330
 
  $pnotes = $r->pnotes($new_pnotes);
331
 
 
332
 
=over 4
333
 
 
334
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
335
 
 
336
 
=item opt arg2: C<$new_pnotes> (C<L<APR::Table|docs::2.0::api::APR::Table>>)
337
 
 
338
 
=item ret: C<$pnotes> (C<L<APR::Table|docs::2.0::api::APR::Table>>)
339
 
 
340
 
 
341
 
=back
342
 
 
343
 
Similar to
344
 
(C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec/C_notes_>>),
345
 
but values can be any perl variables. That also means that it can be
346
 
used only between perl modules.
347
 
 
348
 
 
349
 
 
350
 
 
351
 
 
352
 
=head2 C<no_cache>
353
 
 
354
 
META: Autogenerated - needs to be reviewed/completed
355
 
 
356
 
 
357
 
  $ret = $r->no_cache($flag);
358
 
 
359
 
=over 4
360
 
 
361
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
362
 
 
363
 
=item arg1: C<$flag> (number)
364
 
 
365
 
=item ret: C<$ret> (integer)
366
 
 
367
 
=back
368
 
 
369
 
 
370
 
 
371
 
 
372
 
=head2 C<as_string>
373
 
 
374
 
META: Autogenerated - needs to be reviewed/completed
375
 
 
376
 
  $string = $r->as_string();
377
 
 
378
 
=over 4
379
 
 
380
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
381
 
 
382
 
=item ret: C<$string> (string)
383
 
 
384
 
=back
385
 
 
386
 
 
387
 
 
388
 
 
389
 
=head2 C<get_handlers>
390
 
 
391
 
Returns a reference to a list of handlers enabled for
392
 
a given phase.
393
 
 
394
 
  $handlers_list = $r->get_handlers($hook_name);
395
 
 
396
 
=over 4
397
 
 
398
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
399
 
 
400
 
=item arg1: C<$hook_name> (string)
401
 
 
402
 
a string representing the phase to handle.
403
 
 
404
 
=item ret: C<@handlers> (CODE ref or ref to ARRAY of CODE refs)
405
 
 
406
 
a list of handler subroutines CODE references
407
 
 
408
 
=back
409
 
 
410
 
For example:
411
 
 
412
 
A list of handlers configured to run at the response phase:
413
 
 
414
 
  my @handlers = @{ $r->get_handlers('PerlResponseHandler') || [] };
415
 
 
416
 
 
417
 
 
418
 
 
419
 
=head2 C<push_handlers>
420
 
 
421
 
Add one or more handlers to a list of handlers to be called for a
422
 
given phase.
423
 
 
424
 
  $r->push_handlers($hook_name => \&handler);
425
 
  $r->push_handlers($hook_name => ['Foo::Bar::handler', \&handler2]);
426
 
 
427
 
=over 4
428
 
 
429
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
430
 
 
431
 
=item arg1: C<$hook_name> (string)
432
 
 
433
 
a string representing the phase to handle.
434
 
 
435
 
=item arg2: C<$handlers> (CODE ref or SUB name or ref to an ARRAY of CODE refs)
436
 
 
437
 
a single handler CODE reference or just a name of the subroutine
438
 
(fully qualified unless defined in the current package).
439
 
 
440
 
if more than one passed, use a reference to an array of CODE refs
441
 
and/or subroutine names.
442
 
 
443
 
=item ret: no return value
444
 
 
445
 
=back
446
 
 
447
 
Examples:
448
 
 
449
 
A single handler:
450
 
 
451
 
  $r->push_handlers(PerlResponseHandler => \&handler);
452
 
 
453
 
Multiple handlers:
454
 
 
455
 
  $r->push_handlers(PerlFixupHandler => ['Foo::Bar::handler', \&handler2]);
456
 
 
457
 
Anonymous functions:
458
 
 
459
 
  $r->push_handlers(PerlLogHandler => sub { return Apache::OK });
460
 
 
461
 
 
462
 
 
463
 
 
464
 
=head2 C<set_handlers>
465
 
 
466
 
Set a list of handlers to be called for a given phase. Any previously
467
 
set handlers are forgotten.
468
 
 
469
 
  $r->set_handlers($hook_name => \&handler);
470
 
  $r->set_handlers($hook_name => ['Foo::Bar::handler', \&handler2]);
471
 
  $r->set_handlers($hook_name => []);
472
 
  $r->set_handlers($hook_name => undef);
473
 
 
474
 
=over 4
475
 
 
476
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
477
 
 
478
 
=item arg1: C<$hook_name> (string)
479
 
 
480
 
a string representing the phase to handle.
481
 
 
482
 
=item arg2: C<$handlers> (CODE ref or SUB name or ref to an ARRAY of CODE refs)
483
 
 
484
 
a reference to a single handler CODE reference or just a name of the
485
 
subroutine (fully qualified unless defined in the current package).
486
 
 
487
 
if more than one passed, use a reference to an array of CODE refs
488
 
and/or subroutine names.
489
 
 
490
 
if the argument is C<undef> or [] the list of handlers is reset to
491
 
zero.
492
 
 
493
 
=item ret: no return value
494
 
 
495
 
=back
496
 
 
497
 
Examples:
498
 
 
499
 
A single handler:
500
 
 
501
 
  $r->set_handlers(PerlResponseHandler => \&handler);
502
 
 
503
 
Multiple handlers:
504
 
 
505
 
  $r->set_handlers(PerlFixupHandler => ['Foo::Bar::handler', \&handler2]);
506
 
 
507
 
Anonymous functions:
508
 
 
509
 
  $r->set_handlers(PerlLogHandler => sub { return Apache::OK });
510
 
 
511
 
Reset any previously set handlers:
512
 
 
513
 
  $r->set_handlers(PerlCleanupHandler => []);
514
 
 
515
 
or
516
 
 
517
 
  $r->set_handlers(PerlCleanupHandler => undef);
518
 
 
519
 
 
520
 
 
521
 
 
522
 
=head2 C<set_basic_credentials>
523
 
 
524
 
META: Autogenerated - needs to be reviewed/completed
525
 
 
526
 
 
527
 
 
528
 
  $r->set_basic_credentials($username, $password);
529
 
 
530
 
=over 4
531
 
 
532
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
533
 
 
534
 
=item arg1: C<$username> (string)
535
 
 
536
 
=item arg2: C<$password> (string)
537
 
 
538
 
=item ret: no return value
539
 
 
540
 
=back
541
 
 
542
 
 
543
 
 
544
 
 
545
 
 
546
 
=head2 C<slurp_filename>
547
 
 
548
 
META: Autogenerated - needs to be reviewed/completed
549
 
 
550
 
 
551
 
Return a reference to contents of C<$r-E<gt>filename>.
552
 
 
553
 
  $content = $r->slurp_filename($tainted);
554
 
 
555
 
=over 4
556
 
 
557
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
558
 
 
559
 
=item arg1: C<$tainted> (number)
560
 
 
561
 
By default the returned data is tainted (if run under C<-T>). If an
562
 
optional C<$tainted> flag is set to zero, the data will be marked as
563
 
non-tainted. Do not set this flag to zero unless you know what you are
564
 
doing, you may create a security hole in your program if you do. For
565
 
more information see the I<perlsec> manpage. If you wonder why this
566
 
option is available, it is used internally by the
567
 
C<L<ModPerl::Registry|docs::2.0::api::ModPerl::Registry>> handler and
568
 
friends, because the CGI scripts that it reads are considered safe
569
 
(you could just as well C<require()> them).
570
 
 
571
 
=item ret: C<$content> (scalar)
572
 
 
573
 
=back
574
 
 
575
 
 
576
 
=head2 C<is_perl_option_enabled>
577
 
 
578
 
check whether a directory level PerlOptions flag is enabled or not.
579
 
 
580
 
  $result = $r->is_perl_option_enabled($flag);
581
 
 
582
 
 
583
 
=over 4
584
 
 
585
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
586
 
 
587
 
=item arg1: C<$flag> (string)
588
 
 
589
 
=item ret: C<$result> (integer)
590
 
 
591
 
=back
592
 
 
593
 
For example to check whether the C<SetupEnv> option is enabled for the
594
 
current request (which can be disabled with C<PerlOptions -SetupEnv>)
595
 
and populate the environment variables table if disabled:
596
 
 
597
 
  $r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');
598
 
 
599
 
See also:
600
 
L<PerlOptions|docs::2.0::user::config::config/C_PerlOptions_> and
601
 
L<the equivalent function for server level PerlOptions
602
 
flags|docs::2.0::api::Apache::ServerUtil/C_is_perl_option_enabled_>.
603
 
 
604
 
 
605
 
 
606
 
 
607
 
 
608
 
=head2 C<dir_config>
609
 
 
610
 
dir_config() provides an interface for the per-directory variable
611
 
specified by the C<PerlSetVar> and C<PerlAddVar> directives, and also
612
 
can be manipulated via the C<L<APR::Table|docs::2.0::api::APR::Table>>
613
 
methods.
614
 
 
615
 
  $table  = $r->dir_config();
616
 
  $value  = $r->dir_config($key);
617
 
  @values = $r->dir_config($key);
618
 
  $r->dir_config($key, $val);
619
 
 
620
 
=over 4
621
 
 
622
 
=item obj: C<$r> (C<L<Apache::RequestRec|docs::2.0::api::Apache::RequestRec>>)
623
 
 
624
 
=item opt arg2: C<$key> (string)
625
 
 
626
 
=item opt arg3: C<$val> (string)
627
 
 
628
 
=item ret: C<$ret> (scalar)
629
 
 
630
 
Depends on the passed arguments, see further discussion
631
 
 
632
 
=back
633
 
 
634
 
 
635
 
The keys are case-insensitive.
636
 
 
637
 
  $apr_table = $r->dir_config();
638
 
 
639
 
dir_config() called in a scalar context without the C<$key> argument
640
 
returns a I<HASH> reference blessed into the
641
 
C<L<APR::Table|docs::2.0::api::APR::Table>> class. This object can be
642
 
manipulated via the C<L<APR::Table|docs::2.0::api::APR::Table>>
643
 
methods. For available methods see
644
 
the C<L<APR::Table|docs::2.0::api::APR::Table>> manpage.
645
 
 
646
 
  @values = $r->dir_config($key);
647
 
 
648
 
If the C<$key> argument is passed in the list context a list of all
649
 
matching values will be returned. This method is ineffective for big
650
 
tables, as it does a linear search of the table. Thefore avoid using
651
 
this way of calling dir_config() unless you know that there could be
652
 
more than one value for the wanted key and all the values are wanted.
653
 
 
654
 
  $value = $r->dir_config($key);
655
 
 
656
 
If the C<$key> argument is passed in the scalar context only a single
657
 
value will be returned. Since the table preserves the insertion order,
658
 
if there is more than one value for the same key, the oldest value
659
 
assosiated with the desired key is returned. Calling in the scalar
660
 
context is also much faster, as it'll stop searching the table as soon
661
 
as the first match happens.
662
 
 
663
 
  $r->dir_config($key => $val);
664
 
 
665
 
If the C<$key> and the C<$val> arguments are used, the set() operation
666
 
will happen: all existing values associated with the key C<$key> (and
667
 
the key itself) will be deleted and C<$value> will be placed instead.
668
 
 
669
 
  $r->dir_config($key => undef);
670
 
 
671
 
If C<$val> is I<undef> the unset() operation will happen: all existing
672
 
values associated with the key C<$key> (and the key itself) will be
673
 
deleted.
674
 
 
675
 
 
676
 
 
677
 
 
678
 
 
679
 
=head1 See Also
680
 
 
681
 
L<mod_perl 2.0 documentation|docs::2.0::index>.
682
 
 
683
 
 
684
 
 
685
 
 
686
 
=head1 Copyright
687
 
 
688
 
mod_perl 2.0 and its core modules are copyrighted under
689
 
The Apache Software License, Version 1.1.
690
 
 
691
 
 
692
 
 
693
 
 
694
 
=head1 Authors
695
 
 
696
 
L<The mod_perl development team and numerous
697
 
contributors|about::contributors::people>.
698
 
 
699
 
=cut
700