From 465ee3dd71033feec5bd2385457c21f2774443b5 Mon Sep 17 00:00:00 2001 From: Andreas Granig Date: Fri, 25 Jan 2019 17:28:07 +0100 Subject: [PATCH] TT#51065 Workaround for grafana not setting UTF-8 in Content-Type for js The javascript files contain UTF-8 characters, but the files are sent without a proper encoding set in the Content-Type header. Change-Id: I5df0b854a4d9e8525bf02ec394f9e6264800b2db Signed-off-by: Guillem Jover --- lib/NGCP/Panel/Controller/Grafana.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/NGCP/Panel/Controller/Grafana.pm b/lib/NGCP/Panel/Controller/Grafana.pm index ca731915bf..dba5d02d64 100644 --- a/lib/NGCP/Panel/Controller/Grafana.pm +++ b/lib/NGCP/Panel/Controller/Grafana.pm @@ -1,6 +1,7 @@ package NGCP::Panel::Controller::Grafana; use NGCP::Panel::Utils::Generic qw(:all); use Sipwise::Base; +use Encode qw/decode/; use parent 'Catalyst::Controller'; @@ -43,12 +44,18 @@ sub root :Chained('/') :PathPart('grafana') :Args() { my $body = $c->request->body ? (do { local $/ = undef; $c->request->body->getline }) : ''; $req->content($body); my $res = $ua->request($req); - $c->res->content_type($res->header('Content-Type') // 'text/plain'); + $c->res->content_type($res->content_type // 'text/plain'); if($res->header('Location')) { $c->res->header(Location => $res->header('Location')) } $c->res->status($res->code); - $c->res->body($res->decoded_content); + + if ($c->res->content_type eq "application/javascript") { + # work around broken Grafana not indicating UTF-8 encoding in application/js files + $c->res->body(decode('UTF-8', $res->decoded_content)); + } else { + $c->res->body($res->decoded_content); + } }