Dancer2::Core::Response(3) Response object for Dancer2

VERSION

version 0.200002

ATTRIBUTES

is_encoded

Flag to tell if the content has already been encoded.

is_halted

Flag to tell whether or not the response should continue to be processed.

status

The HTTP status for the response.

content

The content for the response, stored as a string. If a reference is passed, the response will try coerce it to a string via double quote interpolation.

default_content_type

Default mime type to use for the response Content-Type header if nothing was specified

headers

The attribute that store the headers in a HTTP::Headers::Fast object.

That attribute coerces from ArrayRef and defaults to an empty HTTP::Headers::Fast instance.

METHODS

pass

Set has_passed to true.

serializer()

Returns the optional serializer object used to deserialize request parameters

halt

Shortcut to halt the current response by setting the is_halted flag.

encode_content

Encodes the stored content according to the stored content_type. If the content_type is a text format "^text", then no encoding will take place.

Interally, it uses the is_encoded flag to make sure that content is not encoded twice.

If it encodes the content, then it will return the encoded content. In all other cases it returns "false".

new_from_plack

Creates a new response object from a Plack::Response object.

new_from_array

Creates a new response object from a PSGI arrayref.

to_psgi

Converts the response object to a PSGI array.

content_type($type)

A little sugar for setting or accessing the content_type of the response, via the headers.

redirect ($destination, $status)

Sets a header in this response to give a redirect to $destination, and sets the status to $status. If $status is omitted, or false, then it defaults to a status of 302.

error( @args )

    $response->error( message => "oops" );

Creates a Dancer2::Core::Error object with the given @args and throw() it against the response object. Returns the error object.

serialize( $content )

    $response->serialize( $content );

Serialize and return $content with the response's serializer. set content-type accordingly.

header($name)

Return the value of the given header, if present. If the header has multiple values, returns the list of values if called in list context, the first one if in scalar context.

push_header

Add the header no matter if it already exists or not.

    $self->push_header( 'X-Wing' => '1' );

It can also be called with multiple values to add many times the same header with different values:

    $self->push_header( 'X-Wing' => 1, 2, 3 );

headers_to_array($headers)

Convert the $headers to a PSGI ArrayRef.

If no $headers are provided, it will use the current response headers.

AUTHOR

Dancer Core Developers

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Alexis Sukrieh.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.