Skip to content

Commit

Permalink
Allow decoding of application/javascript.
Browse files Browse the repository at this point in the history
This media type has a charset parameter as pe RFC4329, so can
be treated in the same way that XML is.
  • Loading branch information
dracos committed Mar 11, 2018
1 parent 748e046 commit 328b154
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions lib/HTTP/Headers.pm
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ sub content_is_json {
return $ct eq 'application/json' || $ct eq 'text/json' || $ct =~ /\+json$/;
}

sub content_is_javascript {
my $ct = shift->content_type;
# text/javascript is obsolete in RFC4329 but still used.
# No issue including it as well.
return $ct eq 'application/javascript' || $ct eq 'text/javascript';
}

sub referer {
my $self = shift;
if (@_ && $_[0] =~ /#/) {
Expand Down Expand Up @@ -749,6 +756,11 @@ content is XML. This method can't be used to set Content-Type.
Returns TRUE if the Content-Type header field indicate that the
content is JSON. This method can't be used to set Content-Type.
=item $h->content_is_javascript
Returns TRUE if the Content-Type header field indicate that the
content is JavaScript. This method can't be used to set Content-Type.
=item $h->content_encoding
The Content-Encoding header field is used as a modifier to the
Expand Down
2 changes: 1 addition & 1 deletion lib/HTTP/Message.pm
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ sub decoded_content
}
}

if ($self->content_is_text || (my $is_xml = $self->content_is_xml) || $self->content_is_json) {
if ($self->content_is_text || (my $is_xml = $self->content_is_xml) || $self->content_is_json || $self->content_is_javascript) {
my $charset = lc(
$opt{charset} ||
$self->content_type_charset ||
Expand Down

0 comments on commit 328b154

Please sign in to comment.