Apache-Wombat
view release on metacpan or search on metacpan
lib/Apache/Wombat/Response.pm view on Meta::CPAN
B<Parameters:>
=over
=item $code
the HTTP status code
=back
=cut
sub setStatus {
my $self = shift;
my $status = shift;
return 1 if $self->isIncluded();
$self->{apr}->status($status);
$self->{message} = $self->getStatusMessage($status);
return 1;
}
=pod
=back
=head1 PACKAGE METHODS
=over
=item sendHeaders()
Direct Apache API to send a response header, committing the
response. Usually doesn't need to be called by other classes, but will
be called the first time the buffer is flushed.
=cut
sub sendHeaders {
my $self = shift;
my $request = $self->getRequest();
# set up status line
if ($self->{message}) {
$self->{apr}->status_line(join(' ', $self->getStatus(),
$self->{message}));
}
# set up headers
if ($self->{contentType}) {
$self->{apr}->content_type($self->{contentType});
}
if ($self->{contentLength} >= 0) {
$self->{apr}->header_out('Content-Length' => $self->{contentLength});
}
# add session id cookie if necessary
my $sessionCookie = Wombat::Util::RequestUtil->makeSessionCookie($request);
$self->addCookie($sessionCookie) if $sessionCookie;
# set up cookies
for my $cookie ($self->getCookies()) {
my $name = Wombat::Util::CookieTools->getCookieHeaderName($cookie);
my $value = Wombat::Util::CookieTools->getCookieHeaderValue($cookie);
$self->addHeader($name, $value);
}
$self->{apr}->send_http_header();
# Wombat::Globals::DEBUG &&
# $self->debug("sent headers");
unless ($self->{committed}) {
$self->{committed} = 1;
# Wombat::Globals::DEBUG &&
# $self->debug("committed response");
}
return 1;
}
# have to totally override flushBuffer cos the superclass calls
# write() on $self->{handle}, which doesn't exist on Apache::Request;
# use print() instead.
sub flushBuffer {
my $self = shift;
$self->sendHeaders() unless $self->isCommitted();
if ($self->{bufferCount}) {
eval {
$self->{handle}->print($self->{buffer});
};
if ($@) {
my $msg = "flushBuffer: problem writing to output handle";
Servlet::Util::IOException->new($msg);
}
undef $self->{buffer};
$self->{bufferCount} = 0;
unless ($self->{committed}) {
$self->{committed} = 1;
# Wombat::Globals::DEBUG &&
# $self->debug("committed response");
}
}
return 1;
}
=pod
=item getRequestRec()
Return the Apache request record for this Request.
=cut
sub getRequestRec {
my $self = shift;
( run in 0.747 second using v1.01-cache-2.11-cpan-39bf76dae61 )