Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: vti/turnaround
base: a695e0de10
...
head fork: vti/turnaround
compare: 5b979462b9
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
View
1  Makefile.PL
@@ -50,6 +50,7 @@ WriteMakefile(
'String::CamelCase' => '0',
'Text::Caml' => '0',
'YAML::Tiny' => '0',
+ 'MIME::Lite' => '0',
'Test::Class' => '0',
'Test::Fatal' => '0',
View
6 lib/Turnaround/ActionResponseResolver.pm
@@ -6,6 +6,7 @@ use warnings;
use base 'Turnaround::Base';
use JSON ();
+use Encode ();
sub resolve {
my $self = shift;
@@ -13,7 +14,10 @@ sub resolve {
return unless defined $res;
- return [200, ['Content-Type' => 'text/html'], [$res]] unless ref $res;
+ unless (ref $res) {
+ $res = Encode::encode('UTF-8', $res) if Encode::is_utf8($res);
+ return [200, ['Content-Type' => 'text/html'], [$res]];
+ }
return $res if ref $res eq 'ARRAY';
View
19 lib/Turnaround/Response.pm
@@ -5,6 +5,9 @@ use warnings;
use base 'Plack::Response';
+use Encode ();
+use Plack::Util ();
+
sub finalize {
my $self = shift;
@@ -12,7 +15,21 @@ sub finalize {
$self->content_type('text/html');
}
- return $self->SUPER::finalize;
+ my $arrayref = $self->SUPER::finalize;
+
+ if (Plack::Util::is_real_fh($arrayref->[2])) {
+ # TODO
+ }
+ elsif (ref $arrayref->[2] eq 'ARRAY') {
+ $arrayref->[2] =
+ [map { Encode::is_utf8($_) ? Encode::encode('UTF-8', $_) : $_ }
+ @{$arrayref->[2]}];
+ }
+ else {
+ # TODO
+ }
+
+ return $arrayref;
}
1;
View
17 t/core/ActionResponseResolverTest.pm
@@ -2,12 +2,15 @@ package ActionResponseResolverTest;
use strict;
use warnings;
+use utf8;
use base 'TestBase';
use Test::More;
use Test::Fatal;
+use Encode;
+
use Turnaround::Response;
use Turnaround::ActionResponseResolver;
@@ -19,6 +22,20 @@ sub return_undef_on_undef : Test {
ok(not defined $resolver->resolve);
}
+sub return_arrayref_on_string : Test {
+ my $self = shift;
+
+ my $resolver = $self->_build_resolver;
+
+ is_deeply(
+ $resolver->resolve('привет'),
+ [ 200,
+ ['Content-Type' => 'text/html'],
+ [Encode::encode('UTF-8', 'привет')]
+ ]
+ );
+}
+
sub return_arrayref_on_arrayref : Test {
my $self = shift;
View
38 t/core/ResponseTest.pm
@@ -0,0 +1,38 @@
+package ResponseTest;
+
+use strict;
+use warnings;
+use utf8;
+
+use base 'TestBase';
+
+use Test::More;
+use Test::Fatal;
+
+use Encode;
+
+use Turnaround::Response;
+
+sub encode_body : Test {
+ my $self = shift;
+
+ my $res = $self->_build_response(200);
+
+ $res->body('привет');
+
+ is_deeply(
+ $res->finalize,
+ [ 200,
+ ['Content-Type' => 'text/html'],
+ [Encode::encode('UTF-8', 'привет')]
+ ]
+ );
+}
+
+sub _build_response {
+ my $self = shift;
+
+ return Turnaround::Response->new(@_);
+}
+
+1;

No commit comments for this range

Something went wrong with that request. Please try again.