Catalyst-Runtime

 view release on metacpan or  search on metacpan

lib/Catalyst.pm  view on Meta::CPAN

}

=head2 $c->prepare_cookies

Prepares cookies by ensuring that the attribute on the request
object has been built.

=cut

sub prepare_cookies { my $c = shift; $c->request->cookies }

=head2 $c->prepare_headers

Prepares request headers by ensuring that the attribute on the request
object has been built.

=cut

sub prepare_headers { my $c = shift; $c->request->headers }

=head2 $c->prepare_parameters

Prepares parameters.

=cut

sub prepare_parameters {
    my $c = shift;
    $c->prepare_body_parameters;
    $c->engine->prepare_parameters( $c, @_ );
}

=head2 $c->prepare_path

Prepares path and base.

=cut

sub prepare_path { my $c = shift; $c->engine->prepare_path( $c, @_ ) }

=head2 $c->prepare_query_parameters

Prepares query parameters.

=cut

sub prepare_query_parameters {
    my $c = shift;

    $c->engine->prepare_query_parameters( $c, @_ );
}

=head2 $c->log_request

Writes information about the request to the debug logs.  This includes:

=over 4

=item * Request method, path, and remote IP address

=item * Query keywords (see L<Catalyst::Request/query_keywords>)

=item * Request parameters

=item * File uploads

=back

=cut

sub log_request {
    my $c = shift;

    return unless $c->debug;

    my($dump) = grep {$_->[0] eq 'Request' } $c->dump_these;
    my $request = $dump->[1];

    my ( $method, $path, $address ) = ( $request->method, $request->path, $request->address );
    $method ||= '';
    $path = '/' unless length $path;
    $address ||= '';

    $path =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
    $path = decode_utf8($path);

    $c->log->debug(qq/"$method" request for "$path" from "$address"/);

    $c->log_request_headers($request->headers);

    if ( my $keywords = $request->query_keywords ) {
        $c->log->debug("Query keywords are: $keywords");
    }

    $c->log_request_parameters( query => $request->query_parameters, $request->_has_body ? (body => $request->body_parameters) : () );

    $c->log_request_uploads($request);
}

=head2 $c->log_response

Writes information about the response to the debug logs by calling
C<< $c->log_response_status_line >> and C<< $c->log_response_headers >>.

=cut

sub log_response {
    my $c = shift;

    return unless $c->debug;

    my($dump) = grep {$_->[0] eq 'Response' } $c->dump_these;
    my $response = $dump->[1];

    $c->log_response_status_line($response);
    $c->log_response_headers($response->headers);
}

=head2 $c->log_response_status_line($response)

Writes one line of information about the response to the debug logs.  This includes:

=over 4

=item * Response status code

=item * Content-Type header (if present)

=item * Content-Length header (if present)

=back

=cut

sub log_response_status_line {
    my ($c, $response) = @_;

    $c->log->debug(
        sprintf(
            'Response Code: %s; Content-Type: %s; Content-Length: %s',
            $response->status                            || 'unknown',
            $response->headers->header('Content-Type')   || 'unknown',
            $response->headers->header('Content-Length') || 'unknown'
        )
    );
}

=head2 $c->log_response_headers($headers);

Hook method which can be wrapped by plugins to log the response headers.
No-op in the default implementation.



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