--- AnyEvent-HTTP/HTTP.pm 2008/06/04 11:58:36 1.3 +++ AnyEvent-HTTP/HTTP.pm 2008/06/04 12:10:27 1.7 @@ -54,9 +54,14 @@ Executes an HTTP-GET request. See the http_request function for details on additional parameters. -=item http_get $url, $body, key => value..., $cb->($data, $headers) +=item http_head $url, key => value..., $cb->($data, $headers) -Executes an HTTP-POST request with a requets body of C<$bod>. See the +Executes an HTTP-HEAD request. See the http_request function for details on +additional parameters. + +=item http_post $url, $body, key => value..., $cb->($data, $headers) + +Executes an HTTP-POST request with a request body of C<$bod>. See the http_request function for details on additional parameters. =item http_request $method => $url, key => value..., $cb->($data, $headers) @@ -68,7 +73,7 @@ (or C if it wasn't available due to errors), and a hash-ref with response headers as second argument. -All the headers in that has are lowercased. In addition to the response +All the headers in that hash are lowercased. In addition to the response headers, the three "pseudo-headers" C, C and C contain the three parts of the HTTP Status-Line of the same name. @@ -77,6 +82,18 @@ then C<$data> will be C, C<< $headers->{Status} >> will be C<599> and the C pseudo-header will contain an error message. +A typical callback might look like this: + + sub { + my ($body, $hdr) = @_; + + if ($hdr->{Status} =~ /^2/) { + ... everything should be ok + } else { + print "error, $hdr->{Status} $hdr->{Reason}\n"; + } + } + Additional parameters are key-value pairs, and are fully optional. They include: @@ -243,7 +260,10 @@ substr $_, 0, 1, "" for values %hdr; - if ($method ne "HEAD") { + if ($method eq "HEAD") { + %state = (); + $cb->(undef, \%hdr); + } else { if (exists $hdr{"content-length"}) { $_[0]->unshift_read (chunk => $hdr{"content-length"}, sub { # could cache persistent connection now @@ -279,6 +299,11 @@ &http_request } +sub http_head($$;@) { + unshift @_, "HEAD"; + &http_request +} + sub http_post($$$;@) { unshift @_, "POST", "body"; &http_request