… | |
… | |
433 | |
433 | |
434 | for ($set_cookie) { |
434 | for ($set_cookie) { |
435 | # parse NAME=VALUE |
435 | # parse NAME=VALUE |
436 | my @kv; |
436 | my @kv; |
437 | |
437 | |
|
|
438 | # expires is not http-compliant in the original cookie-spec, |
|
|
439 | # we support the official date format and some extensions |
438 | while ( |
440 | while ( |
439 | m{ |
441 | m{ |
440 | \G\s* |
442 | \G\s* |
441 | (?: |
443 | (?: |
442 | expires \s*=\s* ([A-Z][a-z][a-z],\ [^,;]+) |
444 | expires \s*=\s* ([A-Z][a-z][a-z]+,\ [^,;]+) |
443 | | ([^=;,[:space:]]+) \s*=\s* (?: "((?:[^\\"]+|\\.)*)" | ([^=;,[:space:]]*) ) |
445 | | ([^=;,[:space:]]+) \s*=\s* (?: "((?:[^\\"]+|\\.)*)" | ([^=;,[:space:]]*) ) |
444 | ) |
446 | ) |
445 | }gcxsi |
447 | }gcxsi |
446 | ) { |
448 | ) { |
447 | my $name = $2; |
449 | my $name = $2; |
… | |
… | |
963 | Takes a POSIX timestamp (seconds since the epoch) and formats it as a HTTP |
965 | Takes a POSIX timestamp (seconds since the epoch) and formats it as a HTTP |
964 | Date (RFC 2616). |
966 | Date (RFC 2616). |
965 | |
967 | |
966 | =item $timestamp = AnyEvent::HTTP::parse_date $date |
968 | =item $timestamp = AnyEvent::HTTP::parse_date $date |
967 | |
969 | |
968 | Takes a HTTP Date (RFC 2616) or a Cookie date (netscape cookie spec) and |
970 | Takes a HTTP Date (RFC 2616) or a Cookie date (netscape cookie spec) or a |
969 | returns the corresponding POSIX timestamp, or C<undef> if the date cannot |
971 | bunch of minor variations of those, and returns the corresponding POSIX |
970 | be parsed. |
972 | timestamp, or C<undef> if the date cannot be parsed. |
971 | |
973 | |
972 | =item $AnyEvent::HTTP::MAX_RECURSE |
974 | =item $AnyEvent::HTTP::MAX_RECURSE |
973 | |
975 | |
974 | The default value for the C<recurse> request parameter (default: C<10>). |
976 | The default value for the C<recurse> request parameter (default: C<10>). |
975 | |
977 | |
… | |
… | |
1014 | sub parse_date($) { |
1016 | sub parse_date($) { |
1015 | my ($date) = @_; |
1017 | my ($date) = @_; |
1016 | |
1018 | |
1017 | my ($d, $m, $y, $H, $M, $S); |
1019 | my ($d, $m, $y, $H, $M, $S); |
1018 | |
1020 | |
1019 | 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$/) { |
1021 | 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$/) { |
1020 | # RFC 822/1123, required by RFC 2616 (with " ") |
1022 | # RFC 822/1123, required by RFC 2616 (with " ") |
1021 | # cookie dates (with "-") |
1023 | # cookie dates (with "-") |
1022 | |
1024 | |
1023 | ($d, $m, $y, $H, $M, $S) = ($1, $2, $3, $4, $5, $6); |
1025 | ($d, $m, $y, $H, $M, $S) = ($1, $2, $3, $4, $5, $6); |
1024 | |
1026 | |
1025 | } 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$/) { |
1027 | } elsif ($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]?) GMT$/) { |
1026 | # RFC 850 |
1028 | # RFC 850 |
1027 | ($d, $m, $y, $H, $M, $S) = ($1, $2, $3 < 69 ? $3 + 2000 : $3 + 1900, $4, $5, $6); |
1029 | ($d, $m, $y, $H, $M, $S) = ($1, $2, $3 < 69 ? $3 + 2000 : $3 + 1900, $4, $5, $6); |
1028 | |
1030 | |
1029 | } 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])$/) { |
1031 | } 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])$/) { |
1030 | # ISO C's asctime |
1032 | # ISO C's asctime |
1031 | ($d, $m, $y, $H, $M, $S) = ($2, $1, $6, $3, $4, $5); |
1033 | ($d, $m, $y, $H, $M, $S) = ($2, $1, $6, $3, $4, $5); |
1032 | } |
1034 | } |
1033 | # other formats fail in the loop below |
1035 | # other formats fail in the loop below |
1034 | |
1036 | |