=head1 NAME Apache2::Connection - Perl API for Apache connection object =head1 Synopsis use Apache2::Connection (); use Apache2::RequestRec (); my $c = $r->connection; my $c = $r->connection; # is connection still open? $status = $c->aborted; # base server $base_server = $c->base_server(); # needed for creating buckets/brigades $ba = $c->bucket_alloc(); # client's socket $socket = $c->client_socket; # unique connection id $id = $c->id(); # connection filters stack $input_filters = $c->input_filters(); $output_filters = $c->output_filters(); # keep the connection alive? $status = $c->keepalive(); # how many requests served over the current connection $served = $c->keepalives(); # this connection's local and remote socket addresses $local_sa = $c->local_addr(); $remote_sa = $c->remote_addr(); # local and remote hostnames $local_host = $c->local_host(); $remote_host = $c->get_remote_host(); $remote_host = $c->remote_host(); # server and remote client's IP addresses $local_ip = $c->local_ip(); $remote_ip = $c->remote_ip(); # connection level Apache notes $notes = $c->notes(); # this connection's pool $p = $c->pool(); =head1 Description C provides the Perl API for Apache connection record object. =head1 API C provides the following functions and/or methods: =head2 C Check whether the connection is still open $status = $c->aborted(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$status> ( boolean ) true if the connection has been aborted, false if still open =item since: 2.0.00 =back =head2 C Physical server this connection came in on (main server or vhost): $base_server = $c->base_server(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$base_server> ( C> ) =item since: 2.0.00 =back =head2 C The bucket allocator to use for all bucket/brigade creations $ba = $c->bucket_alloc(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$ba> ( C> ) =item since: 2.0.00 =back This object is needed by C> and C> methods/functions. =head2 C Get/set the client socket $socket = $c->client_socket; $prev_socket = $c->client_socket($new_socket); =over 4 =item obj: C<$c> ( C> ) =item opt arg1: C<$new_socket> ( C> object ) If passed a new socket will be set. =item ret: C<$socket> ( C> object ) current client socket if the optional argument C<$new_socket> was passed the previous socket object is returned. =item since: 2.0.00 =back =head2 C Lookup the client's DNS hostname or IP address $remote_host = $c->remote_host(); $remote_host = $c->remote_host($type); $remote_host = $c->remote_host($type, $dir_config); =over 4 =item obj: C<$c> ( C> ) The current connection =item opt arg1: C<$type> ( C> ) The type of lookup to perform: =over =item C will always force a DNS lookup, and also force a double reverse lookup, regardless of the C setting. The result is the (double reverse checked) hostname, or undef if any of the lookups fail. =item C returns the hostname, or C if the hostname lookup fails. It will force a DNS lookup according to the C setting. =item C returns the hostname, or the dotted quad if the hostname lookup fails. It will force a DNS lookup according to the C setting. =item C is like C except that a DNS lookup is never forced. =back Default value is C. =item opt arg2: C<$dir_config> ( C> ) The directory config vector from the request. It's needed to find the container in which the directive C is set. To get one for the current request use Cper_dir_config|docs::2.0::api::Apache2::RequestRec/C_per_dir_config_>>. By default, C is passed, in which case it's the same as if C was set to C. =item ret: C<$remote_host> ( string/undef ) The remote hostname. If the configuration directive B is set to off, this returns the dotted decimal representation of the client's IP address instead. Might return C if the hostname is not known. =item since: 2.0.00 =back The result of C call is cached in Cremote_host|/C_remote_host_>>. If the latter is set, C will return that value immediately, w/o doing any checkups. =head2 C ID of this connection; unique at any point in time $id = $c->id(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$id> (integer) =item since: 2.0.00 =back =head2 C Get/set the first filter in a linked list of protocol level input filters: $input_filters = $c->input_filters(); $prev_input_filters = $c->input_filters($new_input_filters); =over 4 =item obj: C<$c> ( C> ) =item opt arg1: C<$new_input_filters> Set a new value =item ret: C<$input_filters> ( C> ) The first filter in the connection input filters chain. If C<$new_input_filters> was passed, returns the previous value. =item since: 2.0.00 =back For an example see: L =head2 C This method answers the question: Should the the connection be kept alive for another HTTP request after the current request is completed? $status = $c->keepalive(); $status = $c->keepalive($new_status); =over 4 =item obj: C<$c> ( C> ) =item opt arg1: C<$new_status> ( C> ) Normally you should not mess with setting this option when handling the HTTP protocol. If you do (for example when sending your own headers set with Cassbackwards|docs::2.0::api::Apache2::RequestRec/C_assbackwards_>>) -- take a look at the ap_set_keepalive() function in F. =item ret: C<$status> ( C> ) The method does B return true or false, but one of the states which can be compared against (C>). =item since: 2.0.00 =back Unless you set this value yourself when implementing non-HTTP protocols, it's only relevant for HTTP requests. For example: use Apache2::RequestRec (); use Apache2::Connection (); use Apache2::Const -compile => qw(:conn_keepalive); ... my $c = $r->connection; if ($c->keepalive == Apache2::Const::CONN_KEEPALIVE) { # do something } elsif ($c->keepalive == Apache2::Const::CONN_CLOSE) { # do something else } elsif ($c->keepalive == Apache2::Const::CONN_UNKNOWN) { # do yet something else } else { # die "unknown state"; } Notice that new states could be added later by Apache, so your code should make no assumptions and do things only if the desired state matches. =head2 C How many requests were already served over the current connection. $served = $c->keepalives(); $served = $c->keepalives($new_served); =over 4 =item obj: C<$c> ( C> ) =item opt arg1: C<$new_served> (integer) Set the number of served requests over the current connection. Normally you won't do that when handling HTTP requests. (But see below a note regarding Cassbackwards|docs::2.0::api::Apache2::RequestRec/C_assbackwards_>>). =item ret: C<$served> (integer) How many requests were already served over the current connection. In most handlers, but HTTP output filter handlers, that value doesn't count the current request. For the latter it'll count the current request. =item since: 2.0.00 =back This method is only relevant for L connections. The core connection output filter C increments this value when the response headers are sent and it decides that the connection should not be closed (see C). If you send your own set of HTTP headers with Cassbackwards|docs::2.0::api::Apache2::RequestRec/C_assbackwards_>>, which includes the C HTTP response header, you must make sure to increment the C counter. =head2 C Get this connection's local socket address $local_sa = $c->local_addr(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$local_sa> ( C> ) =item since: 2.0.00 =back =head2 C used for ap_get_server_name when UseCanonicalName is set to DNS (ignores setting of HostnameLookups) $local_host = $c->local_host(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$local_host> (string) =item since: 2.0.00 =back META: you probably shouldn't use this method, but ( C> ) if inside request and C<$r> is available. =head2 C server IP address $local_ip = $c->local_ip(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$local_ip> (string) =item since: 2.0.00 =back =head2 C Get/set text notes for the duration of this connection. These notes can be passed from one module to another (not only mod_perl, but modules in any other language): $notes = $c->notes(); $prev_notes = $c->notes($new_notes); =over 4 =item obj: C<$c> ( C> ) =item opt arg1: C<$new_notes> ( C> ) =item ret: C<$notes> ( C> ) the current notes table. if the C<$new_notes> argument was passed, returns the previous value. =item since: 2.0.00 =back Also see Cnotes|docs::2.0::api::Apache2::RequestRec/C_notes_>> =head2 C Get the first filter in a linked list of protocol level output filters: $output_filters = $c->output_filters(); $prev_output_filters = $r->output_filters($new_output_filters); =over 4 =item obj: C<$c> ( C> ) =item opt arg1: C<$new_output_filters> Set a new value =item ret: C<$output_filters> ( C> ) The first filter in the connection output filters chain. If C<$new_output_filters> was passed, returns the previous value. =item since: 2.0.00 =back For an example see: L =head2 C Pool associated with this connection $p = $c->pool(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$p> ( C> ) =item since: 2.0.00 =back =head2 C Get this connection's remote socket address $remote_sa = $c->remote_addr(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$remote_sa> ( C> ) =item since: 2.0.00 =back =head2 C Client's IP address $remote_ip = $c->remote_ip(); $prev_remote_ip = $c->remote_ip($new_remote_ip); =over 4 =item obj: C<$c> ( C> ) =item opt arg1: C<$new_remote_ip> ( string ) If passed a new value will be set =item ret: C<$remote_ip> ( string ) current remote ip address if the optional argument C<$new_remote_ip> was passed the previous value is returned. =item since: 2.0.00 =back =head2 C Client's DNS name: $remote_host = $c->remote_host(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$remote_host> ( string/undef ) If Cget_remote_host|/C_get_remote_host_>> was run it returns the cached value, which is a client DNS name or C<""> if it wasn't found. If the check wasn't run -- C is returned. =item since: 2.0.00 =back It's best to to call Cget_remote_host|/C_get_remote_host_>> instead of directly accessing this variable. =head1 Unsupported API C also provides auto-generated Perl interface for a few other methods which aren't tested at the moment and therefore their API is a subject to change. These methods will be finalized later as a need arises. If you want to rely on any of the following methods please contact the L so we can help each other take the steps necessary to shift the method to an officially supported API. =head2 C Config vector containing pointers to connections per-server config structures $ret = $c->conn_config(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$ret> ( C> ) =item since: 2.0.00 =back =head2 C META: Autogenerated - needs to be reviewed/completed handle to scoreboard information for this connection $sbh = $c->sbh(); =over 4 =item obj: C<$c> ( C> ) =item ret: C<$sbh> (XXX) =item since: 2.0.00 =back META: Not sure how this can be used from mod_perl at the moment. Unless C is extended to provide a hook to read from this variable. =head1 See Also L. =head1 Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. =head1 Authors L. =cut