Apache2-REST

 view release on metacpan or  search on metacpan

lib/Apache2/REST.pm  view on Meta::CPAN

    my $respTxt = $writer->asBytes($resp) ;
    if ( $retCode && ( $retCode  != Apache2::Const::HTTP_OK ) ){
        $r->status($retCode);
    }
    if ( $retCode && $retCode =~ /^2/ ){
        $r->headers_out()->add('Content-length' , length($respTxt)) ;
    }else{
        $r->err_headers_out()->add('Content-length' , length($respTxt)) ;
    }

    binmode STDOUT ;
    print $respTxt  ;
    return  Apache2::Const::OK ;

}


=head1 AUTHORS

Jerome Eteve, C<< <jerome at eteve.net> >>

lib/Apache2/REST/WriterMultipart.pm  view on Meta::CPAN

    my ($self, $resp) = @_;
    return Encode::encode_utf8("");
}

=head2 handleModPerlResponse

Handles writing this response in a mod perl request object at response time.
This also handles the additional work of crafting the correct multipart
boundaries, etc.

Beware, this method switches STDOUT to binmode.

=cut

sub handleModPerlResponse{
    my ($self , $r , $resp , $retCode ) = @_;

    # Add the boundary stuff to the content type value
    my $content_type = $self->mimeType($resp) . "; boundary=\"$BOUNDARY\"";
    $r->content_type($content_type);
    $resp->cleanup();
    
    if ( $retCode && ( $retCode  != Apache2::Const::HTTP_OK ) ){
        $r->status($retCode);
    }

    select(STDOUT);
    $| = 0;
    binmode STDOUT;
    print $self->getPreambleBytes($resp);
    $r->rflush();

    # Note: in the multipart case, each chunk is expected to be
    #       {'mimetype' => '...', 'data' => '...'}
    while (defined (my $nextChunk = $self->getNextPart($resp))) {
        my $mimetype = $nextChunk->{'mimetype'};
        my $data = $nextChunk->{'data'};
        my $content_length = length($data) + 2; # we'll need this plus the \r\n
        print "--$BOUNDARY\r\n";

lib/Apache2/REST/WriterStream.pm  view on Meta::CPAN


sub getPostambleBytes{
    my ($self, $resp) = @_;
    confess("Please implement me in an application subclass");
}

=head2 handleModPerlResponse

Handles writing this response in a mod perl request object at response time.

Beware, this method switches STDOUT to binmode.

=cut

sub handleModPerlResponse{
    my ($self , $r , $resp , $retCode ) = @_;
    $r->content_type($self->mimeType($resp));
    $resp->cleanup();
    
    if ( $retCode && ( $retCode  != Apache2::Const::HTTP_OK ) ){
        $r->status($retCode);
    }

    
    binmode STDOUT;
    print $self->getPreambleBytes($resp);
    $r->rflush();
    while( defined ( my $nextBytes = $self->getNextBytes($resp) ) ){
	print $nextBytes;
	$r->rflush();
    }
    print $self->getPostambleBytes($resp);
    $r->rflush();
    return Apache2::Const::OK;



( run in 0.368 second using v1.01-cache-2.11-cpan-8d75d55dd25 )