Skip to content

Commit

Permalink
added custom response recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 2, 2012
1 parent 2a9d917 commit c4627f5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 0 additions & 5 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -750,11 +750,6 @@ of the response, which is C<text/html;charset=UTF-8> by default.
Finalize response and emit C<after_dispatch> plugin hook, defaults to using a
C<200> response code.
# Stream content directly from file
$c->res->content->asset(Mojo::Asset::File->new(path => '/etc/passwd'));
$c->res->headers->content_type('text/plain');
$c->rendered(200);
=head2 C<req>
my $req = $c->req;
Expand Down
13 changes: 12 additions & 1 deletion lib/Mojolicious/Guides/Rendering.pod
Expand Up @@ -773,12 +773,23 @@ Less commonly used and more powerful features.

=head2 Rendering static files

You can manually render static files from your C<public> directories with
If automatic rendering of static files is not enough, you can also render them
manually from your C<DATA> sections and C<public> directories with
L<Mojolicious::Controller/"render_static">.

$self->res->headers->content_disposition('attachment; filename=bar.png;');
$self->render_static('foo/bar.png');

=head2 Custom responses

For entirely custom responses to, for example, stream content directly from
static files, you can use L<Mojolicious::Controller/"rendered"> to tell the
renderer that a response has been generated.

$self->res->headers->content_type('text/plain');
$self->res->content->asset(Mojo::Asset::File->new(path => '/etc/passwd'));
$self->rendered(200);

=head2 Chunked transfer encoding

For very dynamic content you might not know the response C<Content-Length> in
Expand Down

0 comments on commit c4627f5

Please sign in to comment.