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.61 by root, Thu Dec 30 03:45:01 2010 UTC

806string of the form C<http://host:port> (optionally C<https:...>), croaks 806string of the form C<http://host:port> (optionally C<https:...>), croaks
807otherwise. 807otherwise.
808 808
809To clear an already-set proxy, use C<undef>. 809To clear an already-set proxy, use C<undef>.
810 810
811=item $date = AnyEvent::HTTP::format_date $timestamp
812
813Takes a POSIX timestamp (seconds since the epoch) and formats it as a HTTP
814Date (RFC 2616).
815
816=item $timestamp = AnyEvent::HTTP::parse_date $date
817
818Takes a HTTP Date (RFC 2616) and returns the corresponding POSIX
819timestamp, or C<undef> if the date cannot be parsed.
820
811=item $AnyEvent::HTTP::MAX_RECURSE 821=item $AnyEvent::HTTP::MAX_RECURSE
812 822
813The default value for the C<recurse> request parameter (default: C<10>). 823The default value for the C<recurse> request parameter (default: C<10>).
814 824
815=item $AnyEvent::HTTP::USERAGENT 825=item $AnyEvent::HTTP::USERAGENT
833connections. This number of can be useful for load-leveling. 843connections. This number of can be useful for load-leveling.
834 844
835=back 845=back
836 846
837=cut 847=cut
848
849our @month = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
850our @weekday = qw(Sun Mon Tue Wed Thu Fri Sat);
851
852sub format_date($) {
853 my ($time) = @_;
854
855 # RFC 822/1123 format
856 my ($S, $M, $H, $mday, $mon, $year, $wday, $yday, undef) = gmtime $time;
857
858 sprintf "%s, %02d %s %04d %02d:%02d:%02d GMT",
859 $weekday[$wday], $mday, $month[$mon], $year + 1900,
860 $H, $M, $S;
861}
862
863sub parse_date($) {
864 my ($date) = @_;
865
866 my ($d, $m, $y, $H, $M, $S);
867
868 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$/) {
869 # RFC 822/1123, required by RFC 2616
870 ($d, $m, $y, $H, $M, $S) = ($1, $2, $3, $4, $5, $6);
871
872 } 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$/) {
873 # RFC 850
874 ($d, $m, $y, $H, $M, $S) = ($1, $2, $3 < 69 ? $3 + 2000 : $3 + 1900, $4, $5, $6);
875
876 } 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])$/) {
877 # ISO C's asctime
878 ($d, $m, $y, $H, $M, $S) = ($2, $1, $6, $3, $4, $5);
879 }
880 # other formats fail in the loop below
881
882 for (0..11) {
883 if ($m eq $month[$_]) {
884 require Time::Local;
885 return Time::Local::timegm ($S, $M, $H, $d, $_, $y);
886 }
887 }
888
889 undef
890}
838 891
839sub set_proxy($) { 892sub set_proxy($) {
840 if (length $_[0]) { 893 if (length $_[0]) {
841 $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix 894 $_[0] =~ m%^(https?):// ([^:/]+) (?: : (\d*) )?%ix
842 or Carp::croak "$_[0]: invalid proxy URL"; 895 or Carp::croak "$_[0]: invalid proxy URL";

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines