ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-HTTP/HTTP.pm
(Generate patch)

Comparing AnyEvent-HTTP/HTTP.pm (file contents):
Revision 1.60 by root, Thu Dec 30 02:56:28 2010 UTC vs.
Revision 1.62 by root, Thu Dec 30 04:30:24 2010 UTC

147Whether to recurse requests or not, e.g. on redirects, authentication 147Whether to recurse requests or not, e.g. on redirects, authentication
148retries and so on, and how often to do so. 148retries and so on, and how often to do so.
149 149
150=item headers => hashref 150=item headers => hashref
151 151
152The request headers to use. Currently, C<http_request> may provide its 152The request headers to use, with the header name (I<MUST be in lowercase>)
153own C<Host:>, C<Content-Length:>, C<Connection:> and C<Cookie:> headers 153as key and header value as hash value.
154and will provide defaults for C<User-Agent:> and C<Referer:> (this can be 154
155Currently, http_request> may provide its own C<host>, C<content-length>,
156C<connection> and C<cookie> headers and will provide defaults for
157C<user-agent> and C<referer> (this can be suppressed by using a value of
155suppressed by using C<undef> for these headers in which case they won't be 158C<undef> for these headers in which case they won't be sent at all).
156sent at all).
157 159
158=item timeout => $seconds 160=item timeout => $seconds
159 161
160The time-out to use for various stages - each connect attempt will reset 162The time-out to use for various stages - each connect attempt will reset
161the timeout, as will read or write activity, i.e. this is not an overall 163the timeout, as will read or write activity, i.e. this is not an overall
806string of the form C<http://host:port> (optionally C<https:...>), croaks 808string of the form C<http://host:port> (optionally C<https:...>), croaks
807otherwise. 809otherwise.
808 810
809To clear an already-set proxy, use C<undef>. 811To clear an already-set proxy, use C<undef>.
810 812
813=item $date = AnyEvent::HTTP::format_date $timestamp
814
815Takes a POSIX timestamp (seconds since the epoch) and formats it as a HTTP
816Date (RFC 2616).
817
818=item $timestamp = AnyEvent::HTTP::parse_date $date
819
820Takes a HTTP Date (RFC 2616) and returns the corresponding POSIX
821timestamp, or C<undef> if the date cannot be parsed.
822
811=item $AnyEvent::HTTP::MAX_RECURSE 823=item $AnyEvent::HTTP::MAX_RECURSE
812 824
813The default value for the C<recurse> request parameter (default: C<10>). 825The default value for the C<recurse> request parameter (default: C<10>).
814 826
815=item $AnyEvent::HTTP::USERAGENT 827=item $AnyEvent::HTTP::USERAGENT
833connections. This number of can be useful for load-leveling. 845connections. This number of can be useful for load-leveling.
834 846
835=back 847=back
836 848
837=cut 849=cut
850
851our @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
852our @weekday = qw(Sun Mon Tue Wed Thu Fri Sat);
853
854sub format_date($) {
855 my ($time) = @_;
856
857 # RFC 822/1123 format
858 my ($S, $M, $H, $mday, $mon, $year, $wday, $yday, undef) = gmtime $time;
859
860 sprintf "%s, %02d %s %04d %02d:%02d:%02d GMT",
861 $weekday[$wday], $mday, $month[$mon], $year + 1900,
862 $H, $M, $S;
863}
864
865sub parse_date($) {
866 my ($date) = @_;
867
868 my ($d, $m, $y, $H, $M, $S);
869
870 if ($date =~ /^[A-Z][a-z][a-z], ([0-9][0-9]) ([A-Z][a-z][a-z]) ([0-9][0-9][0-9][0-9]) ([0-9][0-9]):([0-9][0-9]):([0-9][0-9]) GMT$/) {
871 # RFC 822/1123, required by RFC 2616
872 ($d, $m, $y, $H, $M, $S) = ($1, $2, $3, $4, $5, $6);
873
874 } elsif ($date =~ /^[A-Z][a-z]+, ([0-9][0-9])-([A-Z][a-z][a-z])-([0-9][0-9]) ([0-9][0-9]):([0-9][0-9]):([0-9][0-9]) GMT$/) {
875 # RFC 850
876 ($d, $m, $y, $H, $M, $S) = ($1, $2, $3 < 69 ? $3 + 2000 : $3 + 1900, $4, $5, $6);
877
878 } elsif ($date =~ /^[A-Z][a-z][a-z] ([A-Z][a-z][a-z]) ([0-9 ][0-9]) ([0-9][0-9]):([0-9][0-9]):([0-9][0-9]) ([0-9][0-9][0-9][0-9])$/) {
879 # ISO C's asctime
880 ($d, $m, $y, $H, $M, $S) = ($2, $1, $6, $3, $4, $5);
881 }
882 # other formats fail in the loop below
883
884 for (0..11) {
885 if ($m eq $month[$_]) {
886 require Time::Local;
887 return Time::Local::timegm ($S, $M, $H, $d, $_, $y);
888 }
889 }
890
891 undef
892}
838 893
839sub set_proxy($) { 894sub set_proxy($) {
840 if (length $_[0]) { 895 if (length $_[0]) {
841 $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix 896 $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix
842 or Carp::croak "$_[0]: invalid proxy URL"; 897 or Carp::croak "$_[0]: invalid proxy URL";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines