… | |
… | |
147 | Whether to recurse requests or not, e.g. on redirects, authentication |
147 | Whether to recurse requests or not, e.g. on redirects, authentication |
148 | retries and so on, and how often to do so. |
148 | retries and so on, and how often to do so. |
149 | |
149 | |
150 | =item headers => hashref |
150 | =item headers => hashref |
151 | |
151 | |
152 | The request headers to use. Currently, C<http_request> may provide its |
152 | The request headers to use, with the header name (I<MUST be in lowercase>) |
153 | own C<Host:>, C<Content-Length:>, C<Connection:> and C<Cookie:> headers |
153 | as key and header value as hash value. |
154 | and will provide defaults for C<User-Agent:> and C<Referer:> (this can be |
154 | |
|
|
155 | Currently, http_request> may provide its own C<host>, C<content-length>, |
|
|
156 | C<connection> and C<cookie> headers and will provide defaults for |
|
|
157 | C<user-agent> and C<referer> (this can be suppressed by using a value of |
155 | suppressed by using C<undef> for these headers in which case they won't be |
158 | C<undef> for these headers in which case they won't be sent at all). |
156 | sent at all). |
|
|
157 | |
159 | |
158 | =item timeout => $seconds |
160 | =item timeout => $seconds |
159 | |
161 | |
160 | The time-out to use for various stages - each connect attempt will reset |
162 | The time-out to use for various stages - each connect attempt will reset |
161 | the timeout, as will read or write activity, i.e. this is not an overall |
163 | the timeout, as will read or write activity, i.e. this is not an overall |
… | |
… | |
806 | string of the form C<http://host:port> (optionally C<https:...>), croaks |
808 | string of the form C<http://host:port> (optionally C<https:...>), croaks |
807 | otherwise. |
809 | otherwise. |
808 | |
810 | |
809 | To clear an already-set proxy, use C<undef>. |
811 | To clear an already-set proxy, use C<undef>. |
810 | |
812 | |
|
|
813 | =item $date = AnyEvent::HTTP::format_date $timestamp |
|
|
814 | |
|
|
815 | Takes a POSIX timestamp (seconds since the epoch) and formats it as a HTTP |
|
|
816 | Date (RFC 2616). |
|
|
817 | |
|
|
818 | =item $timestamp = AnyEvent::HTTP::parse_date $date |
|
|
819 | |
|
|
820 | Takes a HTTP Date (RFC 2616) and returns the corresponding POSIX |
|
|
821 | timestamp, or C<undef> if the date cannot be parsed. |
|
|
822 | |
811 | =item $AnyEvent::HTTP::MAX_RECURSE |
823 | =item $AnyEvent::HTTP::MAX_RECURSE |
812 | |
824 | |
813 | The default value for the C<recurse> request parameter (default: C<10>). |
825 | The default value for the C<recurse> request parameter (default: C<10>). |
814 | |
826 | |
815 | =item $AnyEvent::HTTP::USERAGENT |
827 | =item $AnyEvent::HTTP::USERAGENT |
… | |
… | |
833 | connections. This number of can be useful for load-leveling. |
845 | connections. This number of can be useful for load-leveling. |
834 | |
846 | |
835 | =back |
847 | =back |
836 | |
848 | |
837 | =cut |
849 | =cut |
|
|
850 | |
|
|
851 | our @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); |
|
|
852 | our @weekday = qw(Sun Mon Tue Wed Thu Fri Sat); |
|
|
853 | |
|
|
854 | sub 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 | |
|
|
865 | sub 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 | |
839 | sub set_proxy($) { |
894 | sub 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"; |