/usr/share/doc/libapache2-mod-perl2-doc/docs/2.0/api/Apache2/RequestUtil.html is in libapache2-mod-perl2-doc 2.0.8+httpd24-r1449661-6ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | <?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:root@localhost" />
</head>
<body style="background-color: white">
<ul id="index">
<li><a href="#NAME">NAME</a></li>
<li><a href="#Synopsis">Synopsis</a></li>
<li><a href="#Description">Description</a></li>
<li><a href="#API">API</a>
<ul>
<li><a href="#add_config">add_config</a></li>
<li><a href="#as_string">as_string</a></li>
<li><a href="#child_terminate">child_terminate</a></li>
<li><a href="#default_type">default_type</a></li>
<li><a href="#dir_config">dir_config</a></li>
<li><a href="#document_root">document_root</a></li>
<li><a href="#get_handlers">get_handlers</a></li>
<li><a href="#get_limit_req_body">get_limit_req_body</a></li>
<li><a href="#get_server_name">get_server_name</a></li>
<li><a href="#get_server_port">get_server_port</a></li>
<li><a href="#get_status_line">get_status_line</a></li>
<li><a href="#is_initial_req">is_initial_req</a></li>
<li><a href="#is_perl_option_enabled">is_perl_option_enabled</a></li>
<li><a href="#location">location</a></li>
<li><a href="#location_merge">location_merge</a></li>
<li><a href="#new">new</a></li>
<li><a href="#no_cache">no_cache</a></li>
<li><a href="#pnotes">pnotes</a></li>
<li><a href="#psignature">psignature</a></li>
<li><a href="#request">request</a></li>
<li><a href="#push_handlers">push_handlers</a></li>
<li><a href="#set_basic_credentials">set_basic_credentials</a></li>
<li><a href="#set_handlers">set_handlers</a></li>
<li><a href="#slurp_filename">slurp_filename</a></li>
</ul>
</li>
<li><a href="#See-Also">See Also</a></li>
<li><a href="#Copyright">Copyright</a></li>
<li><a href="#Authors">Authors</a></li>
</ul>
<h1 id="NAME">NAME</h1>
<p>Apache2::RequestUtil - Perl API for Apache request record utils</p>
<h1 id="Synopsis">Synopsis</h1>
<pre><code> use Apache2::RequestUtil ();
# add httpd config dynamically
$r->add_config(['require valid-user']);
# dump the request object as a string
print $r->as_string();
# default content_type
$content_type = $r->default_type();
# get PerlSetVar/PerlAddVar values
@values = $r->dir_config->get($key);
# get server docroot
$docroot = $r->document_root();
# set server docroot
$r->document_root($new_root);
# what are the registered perl handlers for a given phase
my @handlers = @{ $r->get_handlers('PerlResponseHandler') || [] };
# push a new handler for a given phase
$r->push_handlers(PerlCleanupHandler => \&handler);
# set handlers for a given phase (resetting previous values)
$r->set_handlers(PerlCleanupHandler => []);
# what's the request body limit
$limit = $r->get_limit_req_body();
# server and port names
$server = $r->get_server_name();
$port = $r->get_server_port();
# what string Apache is going to send for a given status code
$status_line = Apache2::RequestUtil::get_status_line(404);
# are we in the main request?
$is_initial = $r->is_initial_req();
# directory level PerlOptions flags lookup
$r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');
# current <Location> value
$location = $r->location();
# merge a <Location> container in a request object
$r->location_merge($location);
# create a new Apache2::RequestRec object
$r = Apache2::RequestRec->new($c);
# tell the client not to cache the response
$r->no_cache($boolean);
# share perl objects by reference like $r->notes
$r->pnotes($key => [$obj1, $obj2]);
# get HTML signature
$sig = $r->psignature($prefix);
# get the global request object (requires PerlOptions +GlobalRequest)
$r = Apache2::RequestUtil->request;
# insert auth credentials into the request as if the client did that
$r->set_basic_credentials($username, $password);
# slurp the contents of $r->filename
my $content = ${ $r->slurp_filename() };
# terminate the current child after this request
$r->child_terminate();</code></pre>
<h1 id="Description">Description</h1>
<p><code>Apache2::RequestUtil</code> provides the <a>Apache request object</a> utilities API.</p>
<h1 id="API">API</h1>
<h2 id="add_config"><code>add_config</code></h2>
<p>Dynamically add Apache configuration at request processing runtime:</p>
<pre><code> $r->add_config($lines);
$r->add_config($lines, $override);
$r->add_config($lines, $override, $path);
$r->add_config($lines, $override, $path, $override_opts);</code></pre>
<p>Configuration directives are processed as if given in a <code><Location></code> block.</p>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-lines-ARRAY-ref">arg1: <code>$lines</code> (ARRAY ref)</dt>
<dd>
<p>An ARRAY reference containing configuration lines per element, without the new line terminators.</p>
</dd>
<dt id="opt-arg2:-override-Apache2::Const-override-constant">opt arg2: <code>$override</code> ( <code><a>Apache2::Const override constant</a></code> )</dt>
<dd>
<p>Which allow-override bits are set</p>
<p>Default value is: <code><a>Apache2::Const::OR_AUTHCFG</a></code></p>
</dd>
<dt id="opt-arg3:-path-string">opt arg3: <code>$path</code> ( string )</dt>
<dd>
<p>Set the <code><a>Apache2::CmdParms object</a></code> <code>path</code> component. This is the path of the <code><Location></code> block. Some directives need this, for example <code>ProxyPassReverse</code>.</p>
<p>If an empty string is passed a <code>NULL</code> pointer is passed further at C-level. This is necessary to make something like this work:</p>
<pre><code> $r->add_config( [
'<Directory />',
'AllowOverride Options AuthConfig',
'</Directory>',
], ~0, '' );</code></pre>
<p>Note: <code>AllowOverride</code> is valid only in directory context.</p>
<p><b>Caution:</b> Some directives need a non-empty path otherwise they cause segfaults. Thus, use the empty path with caution.</p>
<p>Default value is: <code>/</code></p>
</dd>
<dt id="opt-arg4:-override_opts-Apache2::Const-options-constant">opt arg4: <code>$override_opts</code> ( <code><a>Apache2::Const options constant</a></code> )</dt>
<dd>
<p>Apache limits the applicable directives in certain situations with <code>AllowOverride</code>. With Apache 2.2 comes the possibility to enable or disable single options, for example</p>
<pre><code> AllowOverride AuthConfig Options=ExecCGI,Indexes</code></pre>
<p>Internally, this directive is parsed into 2 bit fields that are represented by the <code>$override</code> and <code>$override_opts</code> parameters to <code>add_config</code>. The above example is parsed into an <code>$override</code> with 2 bits set, one for <code>AuthConfig</code> the other for <code>Options</code> and an <code>$override_opts</code> with 2 bits set for ExecCGI and Indexes.</p>
<p>When applying other directives, for example <code>AuthType</code> or <code>Options</code> the appropriate bits in <code>$override</code> must be set. For the <code>Options</code> directive additionally <code>$override_opts</code> bits must be set.</p>
<p>The <code>$override</code> and <code>$override_opts</code> parameters to <code>add_config</code> are valid while applying <code>$lines</code>.</p>
<p><code>$override_opts</code> is new in Apache 2.2. The mod_perl implementation for Apache 2.0 lets you pass the parameter but ignores it.</p>
<p>Default for <code>$override_opts</code> is: <code><a>Apache2::Const::OPT_UNSET</a></code> | <code><a>Apache2::Const::OPT_ALL</a></code> | <code><a>Apache2::Const::OPT_INCNOEXEC</a></code> | <code><a>Apache2::Const::OPT_SYM_OWNER</a></code> | <code><a>Apache2::Const::OPT_MULTI</a></code></p>
<p>That means, all options are allowed.</p>
</dd>
<dt id="ret:-no-return-value">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.00-path-and-override_opts-since-2.0.3">since: 2.0.00, <code>$path</code> and <code>$override_opts</code> since 2.0.3</dt>
<dd>
</dd>
</dl>
<p>See also: <code><a>$s->add_config</a></code></p>
<p>For example:</p>
<pre><code> use Apache2::RequestUtil ();
use Apache2::Access ();
$r->add_config(['require valid-user']);
# this regards the current AllowOverride setting
$r->add_config(['AuthName secret',
'AuthType Basic',
'Options ExecCGI'],
$r->allow_override, $path, $r->allow_override_opts);</code></pre>
<h2 id="as_string"><code>as_string</code></h2>
<p>Dump the request object as a string</p>
<pre><code> $dump = $r->as_string();</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object1">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="ret:-dump-string">ret: <code>$dump</code> ( string )</dt>
<dd>
</dd>
<dt id="since:-2.0.00">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>Dumps various request and response headers (mainly useful for debugging)</p>
<h2 id="child_terminate"><code>child_terminate</code></h2>
<p>Terminate the current worker process as soon as the current request is over</p>
<pre><code> $r->child_terminate();</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object2">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="ret:-no-return-value1">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.001">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>This method is not supported in threaded MPMs</p>
<h2 id="default_type"><code>default_type</code></h2>
<p>Retrieve the value of the DefaultType directive for the current request. If not set <code>text/plain</code> is returned.</p>
<pre><code> $content_type = $r->default_type();</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object3">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
<p>The current request</p>
</dd>
<dt id="ret:-content_type-string">ret: <code>$content_type</code> ( string )</dt>
<dd>
<p>The default type</p>
</dd>
<dt id="since:-2.0.002">since: 2.0.00</dt>
<dd>
</dd>
<dt id="removed-from-the-httpd-API-in-version-2.3.2">removed from the <code>httpd</code> API in version 2.3.2</dt>
<dd>
</dd>
</dl>
<h2 id="dir_config"><code>dir_config</code></h2>
<p><code>$r->dir_config()</code> provides an interface for the per-directory variable specified by the <code>PerlSetVar</code> and <code>PerlAddVar</code> directives, and also can be manipulated via the <code><a>APR::Table</a></code> methods.</p>
<pre><code> $table = $r->dir_config();
$value = $r->dir_config($key);
@values = $r->dir_config->get($key);
$r->dir_config($key, $val);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object4">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="opt-arg2:-key-string">opt arg2: <code>$key</code> ( string )</dt>
<dd>
<p>Key string</p>
</dd>
<dt id="opt-arg3:-val-string">opt arg3: <code>$val</code> ( string )</dt>
<dd>
<p>Value string</p>
</dd>
<dt id="ret">ret: ...</dt>
<dd>
<p>Depends on the passed arguments, see further discussion</p>
</dd>
<dt id="since:-2.0.003">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>The keys are case-insensitive.</p>
<pre><code> $apr_table = $r->dir_config();</code></pre>
<p>dir_config() called in a scalar context without the <code>$key</code> argument returns a <i>HASH</i> reference blessed into the <code><a>APR::Table</a></code> class. This object can be manipulated via the <code><a>APR::Table</a></code> methods. For available methods see the <code><a>APR::Table</a></code> manpage.</p>
<pre><code> $value = $r->dir_config($key);</code></pre>
<p>If the <code>$key</code> argument is passed in the scalar context only a single value will be returned. Since the table preserves the insertion order, if there is more than one value for the same key, the oldest value assosiated with the desired key is returned. Calling in the scalar context is also much faster, as it'll stop searching the table as soon as the first match happens.</p>
<pre><code> @values = $r->dir_config->get($key);</code></pre>
<p>To receive a list of values you must use <code>get()</code> method from the <code><a>APR::Table</a></code> class.</p>
<pre><code> $r->dir_config($key => $val);</code></pre>
<p>If the <code>$key</code> and the <code>$val</code> arguments are used, the set() operation will happen: all existing values associated with the key <code>$key</code> (and the key itself) will be deleted and <code>$value</code> will be placed instead.</p>
<pre><code> $r->dir_config($key => undef);</code></pre>
<p>If <code>$val</code> is <i>undef</i> the unset() operation will happen: all existing values associated with the key <code>$key</code> (and the key itself) will be deleted.</p>
<h2 id="document_root"><code>document_root</code></h2>
<p>Retrieve the document root for this server</p>
<pre><code> $docroot = $r->document_root();
$docroot = $r->document_root($new_root);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object5">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
<p>The current request</p>
</dd>
<dt id="opt-arg1:-new_root">opt arg1: <code>$new_root</code></dt>
<dd>
<p>Sets the document root to a new value <b>only for the duration of the current request</b>.</p>
<p>Note the <a>limited functionality under threaded MPMs</a>.</p>
</dd>
<dt id="ret:-docroot-string">ret: <code>$docroot</code> ( string )</dt>
<dd>
<p>The document root</p>
</dd>
<dt id="since:-2.0.004">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="get_handlers"><code>get_handlers</code></h2>
<p>Returns a reference to a list of handlers enabled for a given phase.</p>
<pre><code> $handlers_list = $r->get_handlers($hook_name);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object6">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-hook_name-string">arg1: <code>$hook_name</code> ( string )</dt>
<dd>
<p>a string representing the phase to handle (e.g. <code>PerlLogHandler</code>)</p>
</dd>
<dt id="ret:-handlers_list-ref-to-an-ARRAY-of-CODE-refs">ret: <code>$handlers_list</code> (ref to an ARRAY of CODE refs)</dt>
<dd>
<p>a list of handler subroutines CODE references</p>
</dd>
<dt id="since:-2.0.005">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>See also: <code><a>$s->add_config</a></code></p>
<p>For example:</p>
<p>A list of handlers configured to run at the response phase:</p>
<pre><code> my @handlers = @{ $r->get_handlers('PerlResponseHandler') || [] };</code></pre>
<h2 id="get_limit_req_body"><code>get_limit_req_body</code></h2>
<p>Return the limit on bytes in request msg body</p>
<pre><code> $limit = $r->get_limit_req_body();</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object7">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
<p>The current request</p>
</dd>
<dt id="ret:-limit-integer">ret: <code>$limit</code> (integer)</dt>
<dd>
<p>the maximum number of bytes in the request msg body</p>
</dd>
<dt id="since:-2.0.006">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="get_server_name"><code>get_server_name</code></h2>
<p>Get the current request's server name</p>
<pre><code> $server = $r->get_server_name();</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object8">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
<p>The current request</p>
</dd>
<dt id="ret:-server-string">ret: <code>$server</code> ( string )</dt>
<dd>
<p>the server name</p>
</dd>
<dt id="since:-2.0.007">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>For example, consruct a hostport string:</p>
<pre><code> use Apache2::RequestUtil ();
my $hostport = join ':', $r->get_server_name, $r->get_server_port;</code></pre>
<h2 id="get_server_port"><code>get_server_port</code></h2>
<p>Get the current server port</p>
<pre><code> $port = $r->get_server_port();</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object9">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
<p>The current request</p>
</dd>
<dt id="ret:-port-integer">ret: <code>$port</code> ( integer )</dt>
<dd>
<p>The server's port number</p>
</dd>
<dt id="since:-2.0.008">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>For example, consruct a hostport string:</p>
<pre><code> use Apache2::RequestUtil ();
my $hostport = join ':', $r->get_server_name, $r->get_server_port;</code></pre>
<h2 id="get_status_line"><code>get_status_line</code></h2>
<p>Return the <code>Status-Line</code> for a given status code (excluding the HTTP-Version field).</p>
<pre><code> $status_line = Apache2::RequestUtil::get_status_line($status);</code></pre>
<dl>
<dt id="arg1:-status-integer">arg1: <code>$status</code> (integer)</dt>
<dd>
<p>The HTTP status code</p>
</dd>
<dt id="ret:-status_line-string">ret: <code>$status_line</code> ( string )</dt>
<dd>
<p>The Status-Line</p>
<p>If an invalid or unknown status code is passed, <code>"500 Internal Server Error"</code> will be returned.</p>
</dd>
<dt id="since:-2.0.009">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>For example:</p>
<pre><code> use Apache2::RequestUtil ();
print Apache2::RequestUtil::get_status_line(400);</code></pre>
<p>will print:</p>
<pre><code> 400 Bad Request</code></pre>
<h2 id="is_initial_req"><code>is_initial_req</code></h2>
<p>Determine whether the current request is the main request or a sub-request</p>
<pre><code> $is_initial = $r->is_initial_req();</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object10">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
<p>A request or a sub-request object</p>
</dd>
<dt id="ret:-is_initial-boolean">ret: <code>$is_initial</code> ( boolean )</dt>
<dd>
<p>If true -- it's the main request, otherwise it's a sub-request</p>
</dd>
<dt id="since:-2.0.0010">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="is_perl_option_enabled"><code>is_perl_option_enabled</code></h2>
<p>check whether a directory level <code>PerlOptions</code> flag is enabled or not.</p>
<pre><code> $result = $r->is_perl_option_enabled($flag);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object11">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-flag-string">arg1: <code>$flag</code> ( string )</dt>
<dd>
</dd>
<dt id="ret:-result-boolean">ret: <code>$result</code> ( boolean )</dt>
<dd>
</dd>
<dt id="since:-2.0.0011">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>For example to check whether the <code>SetupEnv</code> option is enabled for the current request (which can be disabled with <code>PerlOptions -SetupEnv</code>) and populate the environment variables table if disabled:</p>
<pre><code> $r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');</code></pre>
<p>See also: <a>PerlOptions</a> and <a>the equivalent function for server level PerlOptions flags</a>.</p>
<h2 id="location"><code>location</code></h2>
<p>Get the path of the <Location> section from which the current <code>Perl*Handler</code> is being called.</p>
<pre><code> $location = $r->location();</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object12">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="ret:-location-string">ret: <code>$location</code> ( string )</dt>
<dd>
</dd>
<dt id="since:-2.0.0012">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="location_merge"><code>location_merge</code></h2>
<p>Merge a given <code><Location></code> container into the current request object:</p>
<pre><code> $ret = $r->location_merge($location);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object13">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-location-string">arg1: <code>$location</code> ( string )</dt>
<dd>
<p>The argument in a <code><Location></code> section. For example to merge a container:</p>
<pre><code> <Location /foo>
...
</Location></code></pre>
<p>that argument will be <i>/foo</i></p>
</dd>
<dt id="ret:-ret-boolean">ret: <code>$ret</code> ( boolean )</dt>
<dd>
<p>a true value if the merge was successful (i.e. the request <code>$location</code> match was found), otherwise false.</p>
</dd>
<dt id="since:-2.0.0013">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>Useful for insertion of a configuration section into a custom <code>Apache2::RequestRec</code> object, created via the <code>Apache2::RequestRec->new()</code> method. See for example the <a>Command Server protocol example</a>.</p>
<h2 id="new"><code>new</code></h2>
<p>Create a new <code>Apache2::RequestRec</code> object.</p>
<pre><code> $r = Apache2::RequestRec->new($c);
$r = Apache2::RequestRec->new($c, $pool);</code></pre>
<dl>
<dt id="obj:-Apache2::RequestRec-Apache2::RequestRec-class-name">obj: <code>Apache2::RequestRec</code> ( <code><a>Apache2::RequestRec class name</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-c-Apache2::Connection-object">arg1: <code>$c</code> (<code><a>Apache2::Connection object</a></code>)</dt>
<dd>
</dd>
<dt id="opt-arg2:-pool">opt arg2: <code>$pool</code></dt>
<dd>
<p>If no <code>$pool</code> argument is passed, <code>$c->pool</code> is used. That means that the created <code>Apache2::RequestRec</code> object will be valid as long as the connection object is valid.</p>
</dd>
<dt id="ret:-r-Apache2::RequestRec-object">ret: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="since:-2.0.0014">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>It's possible to reuse the HTTP framework features outside the familiar HTTP request cycle. It's possible to write your own full or partial HTTP implementation without needing a running Apache server. You will need the <code>Apache2::RequestRec</code> object in order to be able to reuse the rich functionality supplied via this object.</p>
<p>See for example the <a>Command Server protocol example</a> which reuses HTTP AAA model under non-HTTP protocol.</p>
<h2 id="no_cache"><code>no_cache</code></h2>
<p>Add/remove cache control headers:</p>
<pre><code> $prev_no_cache = $r->no_cache($boolean);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object14">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-boolean-boolean">arg1: <code>$boolean</code> ( boolean )</dt>
<dd>
<p>A true value sets the <code>no_cache</code> request record member to a true value and inserts:</p>
<pre><code> Pragma: no-cache
Cache-control: no-cache</code></pre>
<p>into the response headers, indicating that the data being returned is volatile and the client should not cache it.</p>
<p>A false value unsets the <code>no_cache</code> request record member and the mentioned headers if they were previously set.</p>
</dd>
<dt id="ret:-prev_no_cache-boolean">ret: <code>$prev_no_cache</code> ( boolean )</dt>
<dd>
<p>Should you care, the <code>no_cache</code> request record member value prior to the change is returned.</p>
</dd>
<dt id="since:-2.0.0015">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>This method should be invoked before any response data has been sent out.</p>
<h2 id="pnotes"><code>pnotes</code></h2>
<p>Share Perl variables between Perl HTTP handlers</p>
<pre><code> # to share variables by value and not reference, $val should be a lexical.
$old_val = $r->pnotes($key => $val);
$val = $r->pnotes($key);
$hash_ref = $r->pnotes();</code></pre>
<p><b>Note:</b> sharing variables really means it. The variable is not copied. Only its reference count is incremented. If it is changed after being put in pnotes that change also affects the stored value. The following example illustrates the effect:</p>
<pre><code> my $v=1; my $v=1;
$r->pnotes( 'v'=>$v ); $r->pnotes->{v}=$v;
$v++; $v++;
my $x=$r->pnotes('v'); my $x=$r->pnotes->{v};</code></pre>
<p>In both cases <code>$x</code> is <code>2</code> not <code>1</code>. See also <code>Apache2::SafePnotes</code> on CPAN.</p>
<p>There has been a lot of discussion advocating for pnotes sharing variables by value and not reference. Sharing by reference can create 'spooky action at a distance' effects when the sharing is assumed to share a copy of the value. Tim Bunce offers the following summary and suggestion for sharing by value.</p>
<p>What's wrong with this code:</p>
<pre><code> sub foo {
my ($r, $status, $why) = @_;
$r->pnotes('foo', ($why) ? "$status:$why" : $status);
return;
}</code></pre>
<p>Nothing, except it doesn't work as expected due to this pnotes bug: If the same code is called in a sub-request then the pnote of $r->prev is magically updated at a distance to the same value!</p>
<p>Try to explain why that is to anyone not deeply familiar with perl internals!</p>
<p>The fix is to avoid pnotes taking a ref to the invisible op_targ embededed in the code by passing a simple lexical variable as the actual argument. That can be done in-line like this:</p>
<pre><code> sub mark_as_internally_redirected {
my ($r, $status, $why) = @_;
$r->pnotes('foo', my $tmp = (($why) ? "$status:$why" : $status));
return;
}</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object15">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="opt-arg1:-key-string">opt arg1: <code>$key</code> ( string )</dt>
<dd>
<p>A key value</p>
</dd>
<dt id="opt-arg2:-val-SCALAR">opt arg2: <code>$val</code> ( SCALAR )</dt>
<dd>
<p>Any scalar value (e.g. a reference to an array)</p>
</dd>
<dt id="ret:-3-different-possible-values">ret: (3 different possible values)</dt>
<dd>
<p>if both, <code>$key</code> and <code>$val</code> are passed the previous value for <code>$key</code> is returned if such existed, otherwise <code>undef</code> is returned.</p>
<p>if only <code>$key</code> is passed, the current value for the given key is returned.</p>
<p>if no arguments are passed, a hash reference is returned, which can then be directly accessed without going through the <code>pnotes()</code> interface.</p>
</dd>
<dt id="since:-2.0.0016">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>This method provides functionality similar to (<code><a>Apache2::RequestRec::notes</a></code>), but values can be any Perl variables. That also means that it can be used only between Perl modules.</p>
<p>The values get reset automatically at the end of each HTTP request.</p>
<p>Examples:</p>
<p>Set a key/value pair:</p>
<pre><code> $r->pnotes(foo => [1..5]);</code></pre>
<p>Get the value:</p>
<pre><code> $val = $r->pnotes("foo");</code></pre>
<p><code>$val</code> now contains an array ref containing 5 elements (<code>1..5</code>).</p>
<p>Now change the existing value:</p>
<pre><code> $old_val = $r->pnotes(foo => ['a'..'c']);
$val = $r->pnotes("foo");</code></pre>
<p><code>$old_val</code> now contains an array ref with 5 elements (<code>1..5</code>) and <code>$val</code> contains an array ref with 3 elements <code>'a'</code>, <code>'b'</code>, <code>'c'</code>.</p>
<p>Alternatively you can access the hash reference with all pnotes values:</p>
<pre><code> $pnotes = $r->pnotes;</code></pre>
<p>Now we can read what's in there for the key <i>foo</i>:</p>
<pre><code> $val = $pnotes->{foo};</code></pre>
<p>and as before <code>$val</code> still gives us an array ref with 3 elements <code>'a'</code>, <code>'b'</code>, <code>'c'</code>.</p>
<p>Now we can add elements to it:</p>
<pre><code> push @{ $pnotes{foo} }, 'd'..'f';</code></pre>
<p>and we can try to retrieve them using the hash and non-hash API:</p>
<pre><code> $val1 = $pnotes{foo};
$val2 = $r->pnotes("foo");</code></pre>
<p>Both <code>$val1</code> and <code>$val2</code> contain an array ref with 6 elements (letters 'a' to 'f').</p>
<p>Finally to reset an entry you could just assign <code>undef</code> as a value:</p>
<pre><code> $r->pnotes(foo => undef);</code></pre>
<p>but the entry for the key <i>foo</i> still remains with the value <code>undef</code>. If you really want to completely remove it, use the hash interface:</p>
<pre><code> delete $r->pnotes->{foo};</code></pre>
<h2 id="psignature"><code>psignature</code></h2>
<p>Get HTML describing the address and (optionally) admin of the server.</p>
<pre><code> $sig = $r->psignature($prefix);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec">obj: <code>$r</code> ( <code><a>Apache2::RequestRec</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-prefix-string">arg1: <code>$prefix</code> ( string )</dt>
<dd>
<p>Text which is prepended to the return value</p>
</dd>
<dt id="ret:-sig-string">ret: <code>$sig</code> ( string )</dt>
<dd>
<p>HTML text describing the server. Note that depending on the value of the <code>ServerSignature</code> directive, the function may return the address, including the admin information or nothing at all.</p>
</dd>
<dt id="since:-2.0.0017">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<h2 id="request"><code>request</code></h2>
<p>Get/set the ( <code><a>Apache2::RequestRec object</a></code> ) object for the current request.</p>
<pre><code> $r = Apache2::RequestUtil->request;
Apache2::RequestUtil->request($new_r);</code></pre>
<dl>
<dt id="obj:-Apache2-class-name">obj: <code>Apache2</code> (class name)</dt>
<dd>
<p>The Apache class name</p>
</dd>
<dt id="opt-arg1:-new_r-Apache2::RequestRec-object">opt arg1: <code>$new_r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="ret:-r-Apache2::RequestRec-object1">ret: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="since:-2.0.0018">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>The get-able part of this method is only available if <code><a>PerlOptions +GlobalRequest</a></code> is in effect or if <code>Apache2->request($new_r)</code> was called earlier. So instead of setting <code><a>PerlOptions +GlobalRequest</a></code>, one can set the global request from within the handler.</p>
<h2 id="push_handlers"><code>push_handlers</code></h2>
<p>Add one or more handlers to a list of handlers to be called for a given phase.</p>
<pre><code> $ok = $r->push_handlers($hook_name => \&handler);
$ok = $r->push_handlers($hook_name => ['Foo::Bar::handler', \&handler2]);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object16">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-hook_name-string1">arg1: <code>$hook_name</code> ( string )</dt>
<dd>
<p>the phase to add the handlers to</p>
</dd>
<dt id="arg2:-handlers-CODE-ref-or-SUB-name-or-an-ARRAY-ref">arg2: <code>$handlers</code> ( CODE ref or SUB name or an ARRAY ref )</dt>
<dd>
<p>a single handler CODE reference or just a name of the subroutine (fully qualified unless defined in the current package).</p>
<p>if more than one passed, use a reference to an array of CODE refs and/or subroutine names.</p>
</dd>
<dt id="ret:-ok-boolean">ret: <code>$ok</code> ( boolean )</dt>
<dd>
<p>returns a true value on success, otherwise a false value</p>
</dd>
<dt id="since:-2.0.0019">since: 2.0.00</dt>
<dd>
<p>See also: <code><a>$s->add_config</a></code></p>
<p>Note that to push input/output filters you have to use <code><a>Apache2::Filter</a></code> methods: <code><a>add_input_filter</a></code> and <code><a>add_output_filter</a></code>.</p>
</dd>
</dl>
<p>Examples:</p>
<p>A single handler:</p>
<pre><code> $r->push_handlers(PerlResponseHandler => \&handler);</code></pre>
<p>Multiple handlers:</p>
<pre><code> $r->push_handlers(PerlFixupHandler => ['Foo::Bar::handler', \&handler2]);</code></pre>
<p>Anonymous functions:</p>
<pre><code> $r->push_handlers(PerlLogHandler => sub { return Apache2::Const::OK });</code></pre>
<h2 id="set_basic_credentials"><code>set_basic_credentials</code></h2>
<p>Populate the incoming request headers table (<code>headers_in</code>) with authentication headers for Basic Authorization as if the client has submitted those in first place:</p>
<pre><code> $r->set_basic_credentials($username, $password);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object17">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-username-string">arg1: <code>$username</code> ( string )</dt>
<dd>
</dd>
<dt id="arg2:-password-string">arg2: <code>$password</code> ( string )</dt>
<dd>
</dd>
<dt id="ret:-no-return-value2">ret: no return value</dt>
<dd>
</dd>
<dt id="since:-2.0.0020">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>See for example the <a>Command Server protocol example</a> which reuses HTTP AAA model under non-HTTP protocol.</p>
<h2 id="set_handlers"><code>set_handlers</code></h2>
<p>Set a list of handlers to be called for a given phase. Any previously set handlers are forgotten.</p>
<pre><code> $ok = $r->set_handlers($hook_name => \&handler);
$ok = $r->set_handlers($hook_name => ['Foo::Bar::handler', \&handler2]);
$ok = $r->set_handlers($hook_name => []);
$ok = $r->set_handlers($hook_name => undef);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object18">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-hook_name-string2">arg1: <code>$hook_name</code> ( string )</dt>
<dd>
<p>the phase to set the handlers in</p>
</dd>
<dt id="arg2:-handlers-CODE-ref-or-SUB-name-or-an-ARRAY-ref1">arg2: <code>$handlers</code> (CODE ref or SUB name or an ARRAY ref)</dt>
<dd>
<p>a reference to a single handler CODE reference or just a name of the subroutine (fully qualified unless defined in the current package).</p>
<p>if more than one passed, use a reference to an array of CODE refs and/or subroutine names.</p>
<p>if the argument is <code>undef</code> or <code>[]</code> the list of handlers is reset to zero.</p>
</dd>
<dt id="ret:-ok-boolean1">ret: <code>$ok</code> ( boolean )</dt>
<dd>
<p>returns a true value on success, otherwise a false value</p>
</dd>
<dt id="since:-2.0.0021">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>See also: <code><a>$s->add_config</a></code></p>
<p>Examples:</p>
<p>A single handler:</p>
<pre><code> $r->set_handlers(PerlResponseHandler => \&handler);</code></pre>
<p>Multiple handlers:</p>
<pre><code> $r->set_handlers(PerlFixupHandler => ['Foo::Bar::handler', \&handler2]);</code></pre>
<p>Anonymous functions:</p>
<pre><code> $r->set_handlers(PerlLogHandler => sub { return Apache2::Const::OK });</code></pre>
<p>Reset any previously set handlers:</p>
<pre><code> $r->set_handlers(PerlCleanupHandler => []);</code></pre>
<p>or</p>
<pre><code> $r->set_handlers(PerlCleanupHandler => undef);</code></pre>
<h2 id="slurp_filename"><code>slurp_filename</code></h2>
<p>Slurp the contents of <code>$r->filename</code>:</p>
<pre><code> $content_ref = $r->slurp_filename($tainted);</code></pre>
<dl>
<dt id="obj:-r-Apache2::RequestRec-object19">obj: <code>$r</code> ( <code><a>Apache2::RequestRec object</a></code> )</dt>
<dd>
</dd>
<dt id="arg1:-tainted-number">arg1: <code>$tainted</code> (number)</dt>
<dd>
<p>If the server is run under the tainting mode (<code>-T</code>) which we hope you do, by default the returned data is tainted. If an optional <code>$tainted</code> flag is set to zero, the data will be marked as non-tainted.</p>
<p>Do <b>not</b> set this flag to zero unless you know what you are doing, you may create a security hole in your program if you do. For more information see the <i>perlsec</i> manpage.</p>
<p>If you wonder why this option is available, it is used internally by the <code><a>ModPerl::Registry</a></code> handler and friends, because the CGI scripts that it reads are considered safe (you could just as well <code>require()</code> them).</p>
</dd>
<dt id="ret:-content_ref-SCALAR-ref">ret: <code>$content_ref</code> ( SCALAR ref )</dt>
<dd>
<p>A reference to a string with the contents</p>
</dd>
<dt id="excpt:-APR::Error">excpt: <code><a>APR::Error</a></code></dt>
<dd>
<p>Possible error codes could be: <code><a>APR::Const::EACCES</a></code> (permission problems), <code><a>APR::Const::ENOENT</a></code> (file not found), and others. For checking such error codes, see the documentation for, for example, <code><a>APR::Status::is_EACCES</a></code> and <code><a>APR::Status::is_ENOENT</a></code>.</p>
</dd>
<dt id="since:-2.0.0022">since: 2.0.00</dt>
<dd>
</dd>
</dl>
<p>Note that if you assign to <code>$r->filename</code> you need to <a>update its stat record</a>.</p>
<h1 id="See-Also">See Also</h1>
<p><a>mod_perl 2.0 documentation</a>.</p>
<h1 id="Copyright">Copyright</h1>
<p>mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.</p>
<h1 id="Authors">Authors</h1>
<p><a>The mod_perl development team and numerous contributors</a>.</p>
</body>
</html>
|