summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2012-09-24 10:14:50 -0500
committerJesse Luehrs <doy@tozt.net>2012-09-24 10:23:51 -0500
commit1aedc237afa0840ad9408d646359d197031d4dff (patch)
tree136bf14543db4ab86a7b11db43aae9c91af8775a
parent4310a8e3c45dcad070981eb572ccfcb877f8233f (diff)
downloadweb-request-1aedc237afa0840ad9408d646359d197031d4dff.tar.gz
web-request-1aedc237afa0840ad9408d646359d197031d4dff.zip
don't pass along an undef encoding object
-rw-r--r--lib/Web/Request.pm3
-rw-r--r--t/encoding.t62
2 files changed, 64 insertions, 1 deletions
diff --git a/lib/Web/Request.pm b/lib/Web/Request.pm
index f889f62..6d3538b 100644
--- a/lib/Web/Request.pm
+++ b/lib/Web/Request.pm
@@ -422,7 +422,8 @@ sub new_response {
Class::Load::load_class($self->response_class);
my $res = $self->response_class->new(@_);
- $res->_encoding_obj($self->_encoding_obj);
+ $res->_encoding_obj($self->_encoding_obj)
+ if $self->has_encoding;
return $res;
}
diff --git a/t/encoding.t b/t/encoding.t
index 9c1d39d..95feb6a 100644
--- a/t/encoding.t
+++ b/t/encoding.t
@@ -119,4 +119,66 @@ use Web::Request;
};
}
+{
+ my $app = sub {
+ my ($env) = @_;
+ my $req = Web::Request->new_from_env($env);
+ return $req->new_response(
+ status => 200,
+ content => "café",
+ )->finalize;
+ };
+
+ test_psgi
+ app => $app,
+ client => sub {
+ my ($cb) = @_;
+ my $res = $cb->(GET '/');
+ ok($res->is_success) || diag($res->content);
+ is($res->content, "caf\xe9", "content encoded with latin1");
+ };
+}
+
+{
+ my $app = sub {
+ my ($env) = @_;
+ my $req = Web::Request->new_from_env($env);
+ $req->encoding('UTF-8');
+ return $req->new_response(
+ status => 200,
+ content => "café",
+ )->finalize;
+ };
+
+ test_psgi
+ app => $app,
+ client => sub {
+ my ($cb) = @_;
+ my $res = $cb->(GET '/');
+ ok($res->is_success) || diag($res->content);
+ is($res->content, "caf\xc3\xa9", "content encoded with UTF-8");
+ };
+}
+
+{
+ my $app = sub {
+ my ($env) = @_;
+ my $req = Web::Request->new_from_env($env);
+ $req->encoding(undef);
+ return $req->new_response(
+ status => 200,
+ content => "\x01\x02\xf3",
+ )->finalize;
+ };
+
+ test_psgi
+ app => $app,
+ client => sub {
+ my ($cb) = @_;
+ my $res = $cb->(GET '/');
+ ok($res->is_success) || diag($res->content);
+ is($res->content, "\x01\x02\xf3", "unencoded content");
+ };
+}
+
done_testing;