The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Dendral::HTTP::Response - Perl interface for Apache response variables

SYNOPSIS

# Mod_perl handler
use Dendral::HTTP::Response;

sub handler
{
    my $r = shift;
    my $res = new Dendral::HTTP::Response($r);
    
    #Add cookie to response header
    $res -> add_cookie(name => 'Cooker', 
                       value => {qwe => 'Test',asd => '3'},
                       domain => 'www.Rambler.ru,
                       path => '/123',
                       secure => 1, 
                       expires => '+1M');
                      
    #Set response header 
    $res -> set_header('X-Message' => 'Hello');
    
    #Delete Response header by name
    $res -> delete_header('Set-Cookie');
    
    #Merge header
    $res -> merge_header('X-Temp','123');
    
    #Clear all response header
    $res -> clear_headers();
    
    #Send response headers (Apache 1.x)
    $res -> send_http_header();
    
    #Send file to client
    $res -> send_file('/etc/passwd');
}

DESCRIPTION

Dendral::HTTP::Response is a part of Dendral - fast, reliable and lightweight MVC framework.

METHODS

new - Constructor

Create a new Dendral::HTTP::Response object with an Apache request_rec object:

my $res = new Dendral::HTTP::Response($r);
$res -> add_cookie(name => 'Cooker1', 
                   value => 123,
                   domain => 'www.rambler.ru,
                   path => '/123');

$res -> add_cookie(name => 'Cooker2', 
                   value => {qwe => 'Test',asd => '3'},
                   domain => 'www.Rambler.ru,
                   path => '/1234',
                   expires => '+1M',
                   secure => 1, 
                   httponly => 1);

set_http_code - Set HTTP response code

$res -> set_http_code(404);

get_http_code - Get HTTP response code

my $code = $res -> get_http_code();

send_http_header - Send HTTP response headers

$res -> send_http_header();

redirect - Redirect to uri (Set

$res -> redirect('/index.html');

redirect_permanent - Permanent redirect to uri.

$res -> redirect_permanent('/index.html');

set_header - Set Response header

$res -> set_header('X-Message' => 'Hello');

get_header - Get Response header

$msg = $res -> get_header('X-Message');
#Get hashref of all Headers
$headers = $res -> get_header();

set_content_type - Set Response 'Content-type' header

$res -> set_content_type('text/plain');

get_content_type - Get Response 'Content-type' header

my $content_type = $res -> get_content_type();

delete_header - Delete Response header

$res -> delete_header('X-Message');

merge_header - Merge Response header

$res -> merge_header('X-Message', 'Test');

clear_headers - Clear all Response headers

$res -> clear_headers();

send_file - Send file to client

$res -> send_file('/etc/passwd');

SEE ALSO

perl(1), Apache(3), Dendral::HTTP::Request(1)