You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Bill Moseley <mo...@hank.org> on 2008/12/08 20:20:51 UTC

keep-alives with HTTP 1.0

Apache/2.2.9 (Ubuntu) mod_perl/2.0.4 Perl/v5.10.0

Is there something special I need to do to allow keep-alive responses
for HTTP 1.0 requests?

If I setup a simple httpd.conf with a DocumentRoot and a simple
mod_perl handler I get keep-alive connections as I expect with HTTP
1.1, but with 1.0 I only get keep-alive connections with the static
content.

The issue is I have Perlbal in front of mod_perl and it always sends a
1.0 header to the back end so the mod_perl requests are not kept
alive.


Here's an example:

    $ cat httpd.conf

    <IfModule !mod_perl.c>
        LoadModule perl_module  /usr/lib/apache2/modules/mod_perl.so
    </IfModule>
    <IfModule !mod_mime.c>
        LoadModule mime_module  /usr/lib/apache2/modules/mod_mime.so
    </IfModule>

    ErrorLog    httpd_test.log
    PidFile     httpd_test.pid
    TypesConfig /etc/mime.types
    ServerName  localhost
    Listen      127.0.0.1:10000

    KeepAlive On
    KeepAliveTimeout 20000
    MaxKeepAliveRequests 0
    DocumentRoot /var/www

    <Perl>
        package Foo;
        use Apache2::RequestIO   ();
        use Apache2::RequestRec  ();

        sub handler {
            my $r = shift;
            $r->print( 'This is content' );
            $r->status( 200 );
            $r->content_type( 'text/plain' );
            $r->rflush;
            return Apache2::Const::OK;
        }
    </Perl>


    <Location /foo>
        SetHandler modperl
        PerlResponseHandler Foo
    </Location>



Start the server:

    $ /usr/sbin/apache2 -d $HOME -f httpd.conf -k start


Fetch static content with HTTP 1.0 and get a keep-alive connection.

    $ telnet localhost 10000
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    GET /index.html HTTP/1.0
    Host: localhost:10000
    Keep-Alive: 300
    Connection: keep-alive


    HTTP/1.1 200 OK
    Date: Mon, 08 Dec 2008 18:48:38 GMT
    Server: Apache/2.2.9 (Ubuntu) mod_perl/2.0.4 Perl/v5.10.0
    Last-Modified: Sun, 17 Aug 2008 02:33:33 GMT
    ETag: "e0049-2d-4549eae51b940"
    Accept-Ranges: bytes
    Content-Length: 45
    Keep-Alive: timeout=20000
    Connection: Keep-Alive
    Content-Type: text/html

    <html><body><h1>It works!</h1></body></html>


Fetch mod_perl response with 1.0 and no keep-alive connection:

    $ telnet localhost 10000
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    GET /foo HTTP/1.0
    Host: localhost:10000
    Keep-Alive: 300
    Connection: keep-alive

    HTTP/1.1 200 OK
    Date: Mon, 08 Dec 2008 18:49:26 GMT
    Server: Apache/2.2.9 (Ubuntu) mod_perl/2.0.4 Perl/v5.10.0
    Connection: close
    Content-Type: text/plain


Fetch mod_perl with http 1.1 and do get the keep-alive connection.

    $ telnet localhost 10000
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    GET /foo HTTP/1.1
    Host: localhost:10000
    Keep-Alive: 300
    Connection: keep-alive

    HTTP/1.1 200 OK
    Date: Mon, 08 Dec 2008 18:50:23 GMT
    Server: Apache/2.2.9 (Ubuntu) mod_perl/2.0.4 Perl/v5.10.0
    Keep-Alive: timeout=20000
    Connection: Keep-Alive
    Transfer-Encoding: chunked
    Content-Type: text/plain

    f
    This is content
    0




-- 
Bill Moseley
moseley@hank.org
Sent from my iMutt


Re: keep-alives with HTTP 1.0

Posted by Bill Moseley <mo...@hank.org>.
On Tue, Dec 09, 2008 at 02:33:52PM -0500, Perrin Harkins wrote:
> On Mon, Dec 8, 2008 at 2:20 PM, Bill Moseley <mo...@hank.org> wrote:
> > Is there something special I need to do to allow keep-alive responses
> > for HTTP 1.0 requests?
> 
> Not sure, but there's some info in Apache2::Connection about how it
> determines Keep-Alive and how to check if a connection has it.  More
> in Apach2::RequestRec too.

Need a content-length header for it to work with HTTP 1.0.
The root of the problem was I was using mod_deflate and it was not
returning a content-length, and thus I was not seeing keep-alive
connections.

Thanks,

-- 
Bill Moseley
moseley@hank.org
Sent from my iMutt


Re: keep-alives with HTTP 1.0

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, Dec 8, 2008 at 2:20 PM, Bill Moseley <mo...@hank.org> wrote:
> Is there something special I need to do to allow keep-alive responses
> for HTTP 1.0 requests?

Not sure, but there's some info in Apache2::Connection about how it
determines Keep-Alive and how to check if a connection has it.  More
in Apach2::RequestRec too.

- Perrin