File tree Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Expand file tree Collapse file tree 3 files changed +20
-8
lines changed Original file line number Diff line number Diff line change @@ -103,10 +103,10 @@ The following methods are available:
103
103
104
104
- $mess->decoded\_ content( %options )
105
105
106
- Returns the content with any ` Content-Encoding ` undone and for textual content
107
- the raw content encoded to Perl's Unicode strings. If the ` Content-Encoding `
108
- or ` charset ` of the message is unknown this method will fail by returning
109
- ` undef ` .
106
+ Returns the content with any C< Content-Encoding > undone and for textual content
107
+ (text/ * , XML, or JSON) the raw content encoded to Perl's Unicode strings. If
108
+ the C< Content-Encoding > or C< charset > of the message is unknown this method
109
+ will fail by returning C< undef > .
110
110
111
111
The following options can be specified.
112
112
Original file line number Diff line number Diff line change @@ -405,6 +405,13 @@ sub content_is_xml {
405
405
return 0;
406
406
}
407
407
408
+ sub content_is_json {
409
+ my $ct = shift -> content_type;
410
+ # text/json is not standard but still used by various servers.
411
+ # No issue including it as well.
412
+ return $ct eq ' application/json' || $ct eq ' text/json' || $ct =~ / \+ json$ / ;
413
+ }
414
+
408
415
sub referer {
409
416
my $self = shift ;
410
417
if (@_ && $_ [0] =~ / #/ ) {
@@ -737,6 +744,11 @@ content is XHTML. This method can't be used to set Content-Type.
737
744
Returns TRUE if the Content-Type header field indicate that the
738
745
content is XML. This method can't be used to set Content-Type.
739
746
747
+ =item $h->content_is_json
748
+
749
+ Returns TRUE if the Content-Type header field indicate that the
750
+ content is JSON. This method can't be used to set Content-Type.
751
+
740
752
=item $h->content_encoding
741
753
742
754
The Content-Encoding header field is used as a modifier to the
Original file line number Diff line number Diff line change @@ -351,7 +351,7 @@ sub decoded_content
351
351
}
352
352
}
353
353
354
- if ($self -> content_is_text || (my $is_xml = $self -> content_is_xml)) {
354
+ if ($self -> content_is_text || (my $is_xml = $self -> content_is_xml) || $self -> content_is_json ) {
355
355
my $charset = lc (
356
356
$opt {charset } ||
357
357
$self -> content_type_charset ||
@@ -879,9 +879,9 @@ for details about how charset is determined.
879
879
=item $mess->decoded_content( %options )
880
880
881
881
Returns the content with any C<Content-Encoding > undone and for textual content
882
- the raw content encoded to Perl's Unicode strings. If the C< Content-Encoding >
883
- or C<charset > of the message is unknown this method will fail by returning
884
- C<undef > .
882
+ (text/*, XML, or JSON) the raw content encoded to Perl's Unicode strings. If
883
+ the C< Content-Encoding > or C<charset > of the message is unknown this method
884
+ will fail by returning C<undef > .
885
885
886
886
The following options can be specified.
887
887
You can’t perform that action at this time.
0 commit comments