Cogwheel

 view release on metacpan or  search on metacpan

ex/httpd.pl  view on Meta::CPAN

        predicate => 'has_content',
    );

    has content_length => (
        isa     => 'Int',
        is      => 'rw',
        lazy    => 1,
        default => sub { length( $_[0]->content ) },
    );

    has keep_alive => (
        isa       => 'Bool',
        is        => 'rw',
        predicate => 'has_keep_alive',
    );

    has forwarded_from => (
        isa => 'Str',
        is  => 'rw',
    );

    no Moose;
    __PACKAGE__->meta->make_immutable;
}

ex/httpd.pl  view on Meta::CPAN

        # in request:
        # TODO Accept-Encoding  gzip,deflate
        # TODO Keep-Alive: 300

        my $req   = $self->request;
        my $proto = $req->protocol;
        $r->protocol($proto);

        if ( $proto && $proto eq 'HTTP/1.1' ) {

            # in 1.1, keep-alive is assumed
            $req->keep_alive(1) unless $req->has_keep_alive;
        }
        elsif ( $proto && $proto eq 'HTTP/1.0' ) {
            unless ( $req->has_keep_alive ) {
                my $connection = $req->header('connection');
                if ( $connection && $connection =~ m/^keep-alive$/i ) {
                    $r->header( 'Connection' => 'keep-alive' );
                    $req->keep_alive(1);
                }
                else {
                    $req->keep_alive(0);
                }
            }
        }
        else {
            $req->keep_alive(0);
        }

        # XXX check for content length if keep-alive?
        if ( $self->has_content ) {
            my $out = $self->content;
            $r->content( $self->content );
            $r->header( 'Content-Length' => $self->content_length );
        }

        if ( $con->can('clid') ) {
            if ( my $clid = $con->clid ) {
                $r->header( 'X-Client-ID' => $clid );
            }
        }

        $r->header( 'X-Sprocket-CID' => $con->ID );

        unless ( $req->keep_alive ) {
            $r->header( 'Connection' => 'close' );
            $con->wheel->pause_input();    # no more requests
            $con->send($r);
            $con->close();
        }
        else {

            # TODO set/reset timeout
            $con->send($r);
            $self->{__requests}++;



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