HTML-Mason
view release on metacpan or search on metacpan
lib/HTML/Mason/FakeApache.pm view on Meta::CPAN
my $self = shift;
$self->{the_request} ||= join ' ', $self->method,
( $self->{query}->query_string
? $self->uri . '?' . $self->{query}->query_string
: $self->uri ),
$self->{query}->server_protocol;
}
# Is CGI ever a proxy request?
# sub proxy_req {}
sub header_only { $_[0]->method eq 'HEAD' }
sub protocol { $ENV{SERVER_PROTOCOL} || 'HTTP/1.0' }
sub hostname { $_[0]->{query}->server_name }
# CGI says "use this when using virtual hosts". It falls back to
# CGI->server_port.
sub get_server_port { $_[0]->{query}->virtual_port }
# Fake it by just giving the current time.
sub request_time { time }
sub uri {
my $self = shift;
$self->{uri} ||= $self->{query}->script_name . $self->path_info || '';
}
# Is this available in CGI?
# sub filename {}
# "The $r->location method will return the path of the
# <Location> section from which the current "Perl*Handler"
# is being called." This is irrelevant, I think.
# sub location {}
sub path_info { $_[0]->{query}->path_info }
sub args {
my $self = shift;
if (@_) {
# Assign args here.
}
return $self->{query}->Vars unless wantarray;
# Do more here to return key => arg values.
}
sub headers_in {
my $self = shift;
# Create the headers table if necessary. Decided how to build it based on
# information here:
# http://cgi-spec.golux.com/draft-coar-cgi-v11-03-clean.html#6.1
#
# Try to get as much info as possible from CGI.pm, which has
# workarounds for things like the IIS PATH_INFO bug.
#
$self->{headers_in} ||= HTML::Mason::FakeTable->new
( 'Authorization' => $self->{query}->auth_type, # No credentials though.
'Content-Length' => $ENV{CONTENT_LENGTH},
'Content-Type' =>
( $self->{query}->can('content_type') ?
$self->{query}->content_type :
$ENV{CONTENT_TYPE}
),
# Convert HTTP environment variables back into their header names.
map {
my $k = ucfirst lc;
$k =~ s/_(.)/-\u$1/g;
( $k => $self->{query}->http($_) )
} grep { s/^HTTP_// } keys %ENV
);
# Give 'em the hash list of the hash table.
return wantarray ? %{$self->{headers_in}} : $self->{headers_in};
}
sub header_in {
my ($self, $header) = (shift, shift);
my $h = $self->headers_in;
return @_ ? $h->set($header, shift) : $h->get($header);
}
# The $r->content method will return the entity body
# read from the client, but only if the request content
# type is "application/x-www-form-urlencoded". When
# called in a scalar context, the entire string is
# returned. When called in a list context, a list of
# parsed key => value pairs are returned. *NOTE*: you
# can only ask for this once, as the entire body is read
# from the client.
# Not sure what to do with this one.
# sub content {}
# I think this may be irrelevant under CGI.
# sub read {}
# Use LWP?
sub get_remote_host {}
sub get_remote_logname {}
sub http_header {
my $self = shift;
my $h = $self->headers_out;
my $e = $self->err_headers_out;
my $method = exists $h->{Location} || exists $e->{Location} ?
'redirect' : 'header';
return $self->query->$method(tied(%$h)->cgi_headers,
tied(%$e)->cgi_headers);
}
sub send_http_header {
my $self = shift;
return if $self->http_header_sent;
print STDOUT $self->http_header;
( run in 0.816 second using v1.01-cache-2.11-cpan-39bf76dae61 )