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. The appropriate L<Catalyst::Engine> for your environment
38 will turn the Catalyst::Response into a HTTP Response and return it to the client.
42 =head2 $res->body(<$text|$fh|$iohandle_object)
44 $c->response->body('Catalyst rocks!');
46 Sets or returns the output (text or binary data). If you are returning a large body,
47 you might want to use a L<IO::Handle> type of object (Something that implements the read method
48 in the same fashion), or a filehandle GLOB. Catalyst
49 will write it piece by piece into the response.
51 =head2 $res->content_encoding
53 Shortcut for $res->headers->content_encoding.
55 =head2 $res->content_length
57 Shortcut for $res->headers->content_length.
59 =head2 $res->content_type
61 Shortcut for $res->headers->content_type.
63 This value is typically set by your view or plugin. For example,
64 L<Catalyst::Plugin::Static::Simple> will guess the mime type based on the file
65 it found, while L<Catalyst::View::TT> defaults to C<text/html>.
69 Returns a reference to a hash containing cookies to be set. The keys of the
70 hash are the cookies' names, and their corresponding values are hash
71 references used to construct a L<CGI::Cookie> object.
73 $c->response->cookies->{foo} = { value => '123' };
75 The keys of the hash reference on the right correspond to the L<CGI::Cookie>
76 parameters of the same name, except they are used without a leading dash.
77 Possible parameters are:
95 Shortcut for $res->headers->header.
99 Returns an L<HTTP::Headers> object, which can be used to set headers.
101 $c->response->headers->header( 'X-Catalyst' => $Catalyst::VERSION );
105 Alias for $res->body.
107 =head2 $res->redirect( $url, $status )
109 Causes the response to redirect to the specified URL. The default status is
112 $c->response->redirect( 'http://slashdot.org' );
113 $c->response->redirect( 'http://slashdot.org', 307 );
115 This is a convenience method that sets the Location header to the
116 redirect destination, and then sets the response status. You will
117 want to C< return; > or C< $c->detach() > to interrupt the normal
118 processing flow if you want the redirect to occur straight away.
126 my $location = shift;
127 my $status = shift || 302;
129 $self->location($location);
130 $self->status($status);
133 return $self->location;
138 Sets or returns the HTTP status.
140 $c->response->status(404);
142 =head2 $res->write( $data )
144 Writes $data to the output stream.
148 sub write { shift->{_context}->write(@_); }
152 Catalyst Contributors, see Catalyst.pm
156 This program is free software, you can redistribute it and/or modify
157 it under the same terms as Perl itself.