mod_perl

 view release on metacpan or  search on metacpan

docs/user/handlers/http.pod  view on Meta::CPAN

protect against handlers that called C<$r-E<gt>header_only> (L<which
was ok in 1.3 but is not in 2.0|/Handling_HEAD_Requests>).  Therefore,
C<GET> and C<HEAD> behave identically, except when the content
handler (and/or filters) end up sending no content.  For more details
refer to the lengthy comments in C<ap_http_header_filter()> in
F<httpd-2.0/modules/http/http_protocol.c>).

For more discussion on why it is important to get HEAD requests right,
see these threads from the mod_perl list:

 http://marc.theaimsgroup.com/?l=apache-modperl&m=108647669726915&w=2
 http://marc.theaimsgroup.com/?t=109122984600001&r=1&w=2

as well as this bug report from mozilla, which shows how C<HEAD>
requests are used in the wild:

 http://bugzilla.mozilla.org/show_bug.cgi?id=245447

=item * Not getting C<Content-Length> header with C<HEAD> requests

Even though the spec says that content handlers should send an
identical response for GET and HEAD requests, some folks try to
L<avoid the overhead of generating the response
body|/Handling_HEAD_Requests>, which Apache is going to discard anyway
for HEAD requests. The following discussion assumes that we deal with
a HEAD request.

When Apache sees EOS and no headers and no response body were sent,
C<ap_content_length_filter()> (F<httpd-2.0/server/protocol.c>) sets
C-L to 0. Later on C<ap_http_header_filter()>
(F<httpd-2.0/modules/http/http_protocol.c>) removes the C-L header for
the HEAD requests.

The workaround is to force the sending of the response headers, before
C<EOS> was sent (which happens when the response handler returns). The
simplest solution is to use rflush():

 if ($r->header_only) { # HEAD
     $body_len = calculate_body_len();
     $r->set_content_length($body_len);
     $r->rflush;
 }
 else {                 # GET
     # generate and send the body
 }

now if the handler sets the C-L header it'll be delivered to the
client unmodified.

=back



=head1 Misc Notes

These items will need to be extended and integrated in this or other
HTTP related documents:

=over

=item * front-end back-end setup: mod_proxy+X-Forwarded-For

apache-1.3:

frontend: mod_proxy_add_forward http://develooper.com/code/mpaf/

backend: mod_rpaf (reverse proxy add forward):
http://stderr.net/apache/rpaf/

apache-2.x:

frontend: mod_proxy

backend: mod_rpaf: http://stderr.net/apache/rpaf/

=back



=head1 Extending HTTP Protocol

Extending HTTP under mod_perl is a trivial task.  Look at L<the
example of adding a new method C<EMAIL>|/PerlHeaderParserHandler> for
details.


=head1 HTTP Status Codes

The Hypertext Transfer Protocol (HTTP) is an application-level
protocol for distributed, collaborative, hypermedia information
systems. It is a generic, stateless, protocol which can be used for
many tasks beyond its use for hypertext, such as name servers and
distributed object management systems, through extension of its
request methods, error codes and headers. A feature of HTTP is the
typing and negotiation of data representation, allowing systems to be
built independently of the data being transferred.

HTTP 1.0 is described in Requests For Comments (RFC) 1945. HTTP 1.1 is
the latest version of the specifications and as of this writing HTTP
1.1 is covered in RFC 2616.

When writing mod_perl applications, usually only a small subset of HTTP
response codes is used, but sometimes you need to know others as
well. We will give a short description of each code and you will find
the extended explanation in the appropriate RFC. (Section 9 in RFC
1945 and section 10 in RFC 2616). You can always find the latest link
to these RFCs at the Web Consortium site,
I<http://www.w3.org/Protocols/>.

While HTTP 1.1 is widely supported, HTTP 1.0 still remains the
mainstream standard. Therefore we will supply a summary of the both
versions including the corresponding Apache constants.

In mod_perl these constants can be accessed the 
C<L<Apache::Constants|docs::1.0::api::Apache::Constants>>
package (e.g., to access the HTTP_OK constant use
C<Apache::Constants::HTTP_OK>). See the 
C<L<Apache::Constants|docs::1.0::api::Apache::Constants>> manpage
for more information.

In mod_perl2 these constants can be accessed the 



( run in 0.587 second using v1.01-cache-2.11-cpan-39bf76dae61 )