summaryrefslogtreecommitdiffstats
path: root/lib/Web/Response.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-08-18 08:37:47 -0500
committerJesse Luehrs <doy@tozt.net>2012-08-18 08:37:47 -0500
commit721a07c10b628d163bb3595edddf15e16ce87242 (patch)
tree624495d749d59b48309f9a9b4d25fda6c53ee0bd /lib/Web/Response.pm
parent46138d3c576d67397b41ddf4ca22aefae0d02af3 (diff)
downloadweb-request-721a07c10b628d163bb3595edddf15e16ce87242.tar.gz
web-request-721a07c10b628d163bb3595edddf15e16ce87242.zip
allow undef to mean not decoding at all, and move encoding to ::Response
Diffstat (limited to 'lib/Web/Response.pm')
-rw-r--r--lib/Web/Response.pm29
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/Web/Response.pm b/lib/Web/Response.pm
index bc82526..89c0e26 100644
--- a/lib/Web/Response.pm
+++ b/lib/Web/Response.pm
@@ -3,6 +3,7 @@ use Moose;
# ABSTRACT: common response class for web frameworks
use HTTP::Headers ();
+use Plack::Util ();
use URI::Escape ();
use Web::Request::Types ();
@@ -69,6 +70,15 @@ has cookies => (
default => sub { +{} },
);
+has _encoding_obj => (
+ is => 'ro',
+ isa => 'Object',
+ predicate => 'has_encoding',
+ handles => {
+ encoding => 'name',
+ },
+);
+
sub redirect {
my $self = shift;
my ($url, $status) = @_;
@@ -82,7 +92,7 @@ sub finalize {
$self->_finalize_cookies;
- return [
+ my $res = [
$self->status,
[
map {
@@ -99,6 +109,23 @@ sub finalize {
],
$self->content
];
+
+ return $res unless $self->has_encoding;
+
+ return Plack::Util::response_cb($res, sub {
+ return sub {
+ my $chunk = shift;
+ return unless defined $chunk;
+ return $self->encode($chunk);
+ };
+ });
+}
+
+sub encode {
+ my $self = shift;
+ my ($content) = @_;
+ return $content unless $self->has_encoding;
+ return $self->_encoding_obj->encode($content);
}
sub _finalize_cookies {