Permalink
Browse files

Merge pull request #24 from duckduckgo/dylan/api_response-utf8-encoding

encode utf8 api_responses to bytestream for plack
  • Loading branch information...
2 parents 9a54351 + 9e41603 commit 8a66e8393ea8afbac1546acf60097f874cb50280 @moollaza moollaza committed Oct 7, 2013
Showing with 8 additions and 0 deletions.
  1. +2 −0 lib/App/DuckPAN/Web.pm
  2. +3 −0 lib/App/DuckPAN/WebPublisher.pm
  3. +3 −0 lib/App/DuckPAN/WebStatic.pm
View
@@ -129,6 +129,8 @@ sub request {
));
if ($res->is_success) {
$body = $res->decoded_content;
+ # Encode utf8 api_responses to bytestream for Plack.
+ utf8::encode $body if utf8::is_utf8 $body;
warn "Cannot use wrap_jsonp_callback and wrap_string callback at the same time!" if $rewrite->wrap_jsonp_callback && $rewrite->wrap_string_callback;
if ($rewrite->wrap_jsonp_callback && $rewrite->callback) {
$body = $rewrite->callback.'('.$body.');';
@@ -89,6 +89,9 @@ sub request {
}
}
+ # This could cause issues with incorrectly encoded data as Plack expects a
+ # raw bytestream. We should find the root of this issue and reencode
+ # offending strings.
Encode::_utf8_off($body);
$response->body($body);
return $response;
@@ -88,6 +88,9 @@ sub request {
}
}
+ # This could cause issues with incorrectly encoded data as Plack expects a
+ # raw bytestream. We should find the root of this issue and reencode
+ # offending strings.
Encode::_utf8_off($body);
$response->body($body);
return $response;

0 comments on commit 8a66e83

Please sign in to comment.