1HTTP::Response::EncodinUgs(e3r)Contributed Perl DocumentHaTtTiPo:n:Response::Encoding(3)
2
3
4
6 HTTP::Response::Encoding - Adds encoding() to HTTP::Response
7
9 $Id: Encoding.pm,v 0.6 2009/07/28 21:25:25 dankogai Exp dankogai $
10
12 use LWP::UserAgent;
13 use HTTP::Response::Encoding;
14
15 my $ua = LWP::UserAgent->new();
16 my $res = $ua->get("http://www.example.com/");
17 warn $res->encoding;
18
20 Nothing.
21
23 This module adds the following methods to HTTP::Response objects.
24
25 "$res->charset"
26 Tells the charset exactly as appears in the "Content-Type:" header.
27 Note that the presence of the charset does not guarantee if the
28 response content is decodable via Encode.
29
30 To normalize this, you should try
31
32 $res->encoder->mime_name; # with Encode 2.21 or above
33
34 or
35
36 use I18N::Charset;
37 # ...
38 mime_charset_name($res->encoding);
39
40 "$res->encoder"
41 Returns the corresponding encoder object or undef if it can't.
42
43 "$res->encoding"
44 Tells the content encoding in the canonical name in Encode. Returns
45 undef if it can't.
46
47 For most cases, you are more likely to successfully find encoding
48 after GET than HEAD. HTTP::Response is smart enough to parse
49
50 <meta http-equiv="Content-Type" content="text/html; charset=whatever"/>
51
52 But you need the content to let HTTP::Response parse it. If you
53 don't want to retrieve the whole content but interested in its
54 encoding, try something like below;
55
56 my $req = HTTP::Request->new(GET => $uri);
57 $req->headers->header(Range => "bytes=0-4095"); # just 1st 4k
58 my $res = $ua->request($req);
59 warn $res->encoding;
60
61 "$res->decoded_content"
62 Discontinued since HTTP::Message already has this method.
63
64 See HTTP::Message for details.
65
67 To install this module, run the following commands:
68
69 perl Makefile.PL
70 make
71 make test
72 make install
73
75 Dan Kogai, "<dankogai at dan.co.jp>"
76
78 Please report any bugs or feature requests to
79 "bug-http-response-encoding at rt.cpan.org", or through the web
80 interface at
81 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTTP-Response-Encoding
82 <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=HTTP-Response-
83 Encoding>. I will be notified, and then you'll automatically be
84 notified of progress on your bug as I make changes.
85
87 You can find documentation for this module with the perldoc command.
88
89 perldoc HTTP::Response::Encoding
90
91 You can also look for information at:
92
93 · AnnoCPAN: Annotated CPAN documentation
94
95 http://annocpan.org/dist/HTTP-Response-Encoding
96 <http://annocpan.org/dist/HTTP-Response-Encoding>
97
98 · CPAN Ratings
99
100 http://cpanratings.perl.org/d/HTTP-Response-Encoding
101 <http://cpanratings.perl.org/d/HTTP-Response-Encoding>
102
103 · RT: CPAN's request tracker
104
105 http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTTP-Response-Encoding
106 <http://rt.cpan.org/NoAuth/Bugs.html?Dist=HTTP-Response-Encoding>
107
108 · Search CPAN
109
110 http://search.cpan.org/dist/HTTP-Response-Encoding
111 <http://search.cpan.org/dist/HTTP-Response-Encoding>
112
114 GAAS for LWP.
115
116 MIYAGAWA for suggestions.
117
119 Copyright 2007 Dan Kogai, all rights reserved.
120
121 This program is free software; you can redistribute it and/or modify it
122 under the same terms as Perl itself.
123
124
125
126perl v5.12.0 2009-07-28 HTTP::Response::Encoding(3)