.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "docs::api::Apache2::URI 3pm" .TH docs::api::Apache2::URI 3pm 2024-03-29 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Apache2::URI \- Perl API for manipulating URIs .SH Synopsis .IX Header "Synopsis" .Vb 1 \& use Apache2::URI (); \& \& $hostport = $r\->construct_server(); \& $hostport = $r\->construct_server($hostname); \& $hostport = $r\->construct_server($hostname, $port); \& $hostport = $r\->construct_server($hostname, $port, $pool); \& \& $url = $r\->construct_url(); \& $url = $r\->construct_url($rel_uri); \& $url = $r\->construct_url($rel_uri, $pool); \& \& $parsed_uri = $r\->parse_uri($uri); \& \& $parsed_uri = $r\->parsed_uri(); \& \& $url = join \*(Aq%20\*(Aq, qw(one two three); \& Apache2::URI::unescape_url($url); .Ve .SH Description .IX Header "Description" While \f(CW\*(C`APR::URI\*(C'\fR provides a generic API to dissect, adjust and put together any given URI string, \f(CW\*(C`Apache2::URI\*(C'\fR provides an API specific to Apache, by taking the information directly from the \f(CW$r\fR object. Therefore when manipulating the URI of the current HTTP request usually methods from both classes are used. .SH API .IX Header "API" \&\f(CW\*(C`Apache2::URI\*(C'\fR provides the following functions and methods: .ie n .SS """construct_server""" .el .SS \f(CWconstruct_server\fP .IX Subsection "construct_server" Construct a string made of hostname and port .PP .Vb 4 \& $hostport = $r\->construct_server(); \& $hostport = $r\->construct_server($hostname); \& $hostport = $r\->construct_server($hostname, $port); \& $hostport = $r\->construct_server($hostname, $port, $pool); .Ve .ie n .IP "obj: $r ( ""Apache2::RequestRec object"" )" 4 .el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4 .IX Item "obj: $r ( Apache2::RequestRec object )" The current request object .ie n .IP "opt arg1: $hostname ( string )" 4 .el .IP "opt arg1: \f(CW$hostname\fR ( string )" 4 .IX Item "opt arg1: $hostname ( string )" The hostname of the server. .Sp If that argument is not passed, \&\f(CW\*(C`$r\->get_server_name\*(C'\fR is used. .ie n .IP "opt arg2: $port ( string )" 4 .el .IP "opt arg2: \f(CW$port\fR ( string )" 4 .IX Item "opt arg2: $port ( string )" The port the server is running on. .Sp If that argument is not passed, \&\f(CW\*(C`$r\->get_server_port\*(C'\fR is used. .ie n .IP "opt arg3: $pool ( ""APR::Pool object"" )" 4 .el .IP "opt arg3: \f(CW$pool\fR ( \f(CWAPR::Pool object\fR )" 4 .IX Item "opt arg3: $pool ( APR::Pool object )" The pool to allocate the string from. .Sp If that argument is not passed, \&\f(CW\*(C`$r\->pool\*(C'\fR is used. .ie n .IP "ret: $hostport ( string )" 4 .el .IP "ret: \f(CW$hostport\fR ( string )" 4 .IX Item "ret: $hostport ( string )" The server's hostport string .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP Examples: .IP \(bu 4 Assuming that: .Sp .Vb 2 \& $r\->get_server_name == "localhost"; \& $r\->get_server_port == 8001; .Ve .Sp The code: .Sp .Vb 1 \& $hostport = $r\->construct_server(); .Ve .Sp returns a string: .Sp .Vb 1 \& localhost:8001 .Ve .IP \(bu 4 The following code sets the values explicitly: .Sp .Vb 1 \& $hostport = $r\->construct_server("my.example.com", 8888); .Ve .Sp and it returns a string: .Sp .Vb 1 \& my.example.com:8888 .Ve .ie n .SS """construct_url""" .el .SS \f(CWconstruct_url\fP .IX Subsection "construct_url" Build a fully qualified URL from the uri and information in the request rec: .PP .Vb 3 \& $url = $r\->construct_url(); \& $url = $r\->construct_url($rel_uri); \& $url = $r\->construct_url($rel_uri, $pool); .Ve .ie n .IP "obj: $r ( ""Apache2::RequestRec object"" )" 4 .el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4 .IX Item "obj: $r ( Apache2::RequestRec object )" The current request object .ie n .IP "opt arg1: $rel_uri ( string )" 4 .el .IP "opt arg1: \f(CW$rel_uri\fR ( string )" 4 .IX Item "opt arg1: $rel_uri ( string )" The path to the requested file (it may include a concatenation of \&\fIpath\fR, \fIquery\fR and \fIfragment\fR components). .Sp If that argument is not passed, \&\f(CW\*(C`$r\->uri\*(C'\fR is used. .ie n .IP "opt arg2: $pool ( ""APR::Pool object"" )" 4 .el .IP "opt arg2: \f(CW$pool\fR ( \f(CWAPR::Pool object\fR )" 4 .IX Item "opt arg2: $pool ( APR::Pool object )" The pool to allocate the URL from .Sp If that argument is not passed, \&\f(CW\*(C`$r\->pool\*(C'\fR is used. .ie n .IP "ret: $url ( string )" 4 .el .IP "ret: \f(CW$url\fR ( string )" 4 .IX Item "ret: $url ( string )" A fully qualified URL .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP Examples: .IP \(bu 4 Assuming that the request was .Sp .Vb 1 \& http://localhost.localdomain:8529/test?args .Ve .Sp The code: .Sp .Vb 1 \& my $url = $r\->construct_url; .Ve .Sp returns the string: .Sp .Vb 1 \& http://localhost.localdomain:8529/test .Ve .Sp notice that the query (args) component is not in the string. You need to append it manually if it's needed. .IP \(bu 4 Assuming that the request was .Sp .Vb 1 \& http://localhost.localdomain:8529/test?args .Ve .Sp The code: .Sp .Vb 2 \& my $rel_uri = "/foo/bar?tar"; \& my $url = $r\->construct_url($rel_uri); .Ve .Sp returns the string: .Sp .Vb 1 \& http://localhost.localdomain:8529/foo/bar?tar .Ve .ie n .SS """parse_uri""" .el .SS \f(CWparse_uri\fP .IX Subsection "parse_uri" Break apart URI (affecting the current request's uri components) .PP .Vb 1 \& $r\->parse_uri($uri); .Ve .ie n .IP "obj: $r ( ""Apache2::RequestRec object"" )" 4 .el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4 .IX Item "obj: $r ( Apache2::RequestRec object )" The current request object .ie n .IP "arg1: $uri ( string )" 4 .el .IP "arg1: \f(CW$uri\fR ( string )" 4 .IX Item "arg1: $uri ( string )" The uri to break apart .IP "ret: no return value" 4 .IX Item "ret: no return value" .PD 0 .IP warning: 4 .IX Item "warning:" .PD This method has several side-effects explained below .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP This method call has the following side-effects: .IP 1. 4 sets \f(CW\*(C`$r\->args\*(C'\fR to the rest after \f(CW\*(Aq?\*(Aq\fR if such exists in the passed \f(CW$uri\fR, otherwise sets it to \f(CW\*(C`undef\*(C'\fR. .IP 2. 4 sets \f(CW\*(C`$r\->uri\*(C'\fR to the passed \f(CW$uri\fR without the \&\f(CW\*(C`$r\->args\*(C'\fR part. .IP 3. 4 sets \&\f(CW\*(C`$r\->hostname\*(C'\fR (if not set already) using the (\f(CW\*(C`scheme://host:port\*(C'\fR) parts of the passed \f(CW$uri\fR. .ie n .SS """parsed_uri""" .el .SS \f(CWparsed_uri\fP .IX Subsection "parsed_uri" Get the current request's parsed uri object .PP .Vb 1 \& my $uri = $r\->parsed_uri(); .Ve .ie n .IP "obj: $r ( ""Apache2::RequestRec object"" )" 4 .el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4 .IX Item "obj: $r ( Apache2::RequestRec object )" The current request object .ie n .IP "ret: $uri ( ""APR::URI object"" )" 4 .el .IP "ret: \f(CW$uri\fR ( \f(CWAPR::URI object\fR )" 4 .IX Item "ret: $uri ( APR::URI object )" The parsed uri .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" This object is suitable for using with \f(CW\*(C`APR::URI::rpath\*(C'\fR .ie n .SS """unescape_url""" .el .SS \f(CWunescape_url\fP .IX Subsection "unescape_url" Unescape URLs .PP .Vb 1 \& Apache2::URI::unescape_url($url); .Ve .ie n .IP "obj: $url ( string )" 4 .el .IP "obj: \f(CW$url\fR ( string )" 4 .IX Item "obj: $url ( string )" The URL to unescape .IP "ret: no return value" 4 .IX Item "ret: no return value" The argument \f(CW$url\fR is now unescaped .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP Example: .PP .Vb 2 \& my $url = join \*(Aq%20\*(Aq, qw(one two three); \& Apache2::URI::unescape_url($url); .Ve .PP \&\f(CW$url\fR now contains the string: .PP .Vb 1 \& "one two three"; .Ve .SH "See Also" .IX Header "See Also" \&\f(CW\*(C`APR::URI\*(C'\fR, mod_perl 2.0 documentation. .SH Copyright .IX Header "Copyright" mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. .SH Authors .IX Header "Authors" The mod_perl development team and numerous contributors.