1 package Catalyst::Response;
4 use base 'Class::Accessor::Fast';
6 __PACKAGE__->mk_accessors(qw/cookies body headers location status/);
10 sub content_encoding { shift->headers->content_encoding(@_) }
11 sub content_length { shift->headers->content_length(@_) }
12 sub content_type { shift->headers->content_type(@_) }
13 sub header { shift->headers->header(@_) }
17 Catalyst::Response - stores output responding to the current client request
23 $res->content_encoding;
36 This is the Catalyst Response class, which provides methods for responding to
37 the current client request.
41 =head2 $res->body($text)
43 $c->response->body('Catalyst rocks!');
45 Sets or returns the output (text or binary data).
47 =head2 $res->content_encoding
49 Shortcut for $res->headers->content_encoding.
51 =head2 $res->content_length
53 Shortcut for $res->headers->content_length.
55 =head2 $res->content_type
57 Shortcut for $res->headers->content_type.
59 This value is typically set by your view or plugin. For example,
60 L<Catalyst::Plugin::Static::Simple> will guess the mime type based on the file
61 it found, while L<Catalyst::View::TT> defaults to C<text/html>.
65 Returns a reference to a hash containing cookies to be set. The keys of the
66 hash are the cookies' names, and their corresponding values are hash
67 references used to construct a L<CGI::Cookie> object.
69 $c->response->cookies->{foo} = { value => '123' };
71 The keys of the hash reference on the right correspond to the L<CGI::Cookie>
72 parameters of the same name, except they are used without a leading dash.
73 Possible parameters are:
87 Shortcut for $res->headers->header.
91 Returns an L<HTTP::Headers> object, which can be used to set headers.
93 $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
99 =head2 $res->redirect( $url, $status )
101 Causes the response to redirect to the specified URL.
103 $c->response->redirect( 'http://slashdot.org' );
104 $c->response->redirect( 'http://slashdot.org', 307 );
112 my $location = shift;
113 my $status = shift || 302;
115 $self->location($location);
116 $self->status($status);
119 return $self->location;
124 Sets or returns the HTTP status.
126 $c->response->status(404);
128 =head2 $res->write( $data )
130 Writes $data to the output stream.
134 sub write { shift->{_context}->write(@_); }
138 Sebastian Riedel, C<sri@cpan.org>
140 Marcus Ramberg, C<mramberg@cpan.org>
144 This program is free software, you can redistribute it and/or modify
145 it under the same terms as Perl itself.