AnyEvent-HTTP-Message
view release on metacpan or search on metacpan
lib/AnyEvent/HTTP/Request.pm view on Meta::CPAN
# vim: set ts=2 sts=2 sw=2 expandtab smarttab:
#
# This file is part of AnyEvent-HTTP-Message
#
# This software is copyright (c) 2012 by Randy Stauner.
#
# This is free software; you can redistribute it and/or modify it under
# the same terms as the Perl 5 programming language system itself.
#
use strict;
use warnings;
package AnyEvent::HTTP::Request;
{
$AnyEvent::HTTP::Request::VERSION = '0.302';
}
BEGIN {
$AnyEvent::HTTP::Request::AUTHORITY = 'cpan:RWSTAUNER';
}
# ABSTRACT: HTTP Request object for AnyEvent::HTTP
use parent 'AnyEvent::HTTP::Message';
sub new {
my $class = shift;
my $self = $class->SUPER::new(@_);
$self->{method} = uc $self->{method};
return $self;
}
sub parse_args {
my $self = shift;
$self->_error(
q[expects an odd number of arguments:],
q[($method, $uri, (key => value, ...)*, \&callback)]
)
unless @_ & 1; ## no critic BitwiseOperators
my $args = {
method => shift,
uri => shift,
cb => pop,
params => { @_ },
};
# remove these from params
$args->{$_} = delete $args->{params}{$_}
for qw( body headers );
return $args;
}
sub from_http_message {
my ($self, $req, $extra) = @_;
my $args = {
method => $req->method,
uri => $req->uri,
headers => $self->_hash_http_headers($req->headers),
body => $req->content,
(ref($extra) eq 'HASH' ? %$extra : ()),
};
# rt-85665: AE:H will provide it's own content-length.
# If you provide your own it may persist incorrectly across redirects.
delete $args->{headers}{$_}
for qw( content-length );
return $args;
}
sub args {
my ($self) = @_;
return (
$self->method => $self->uri,
body => $self->body,
headers => $self->headers,
%{ $self->params },
$self->cb,
);
}
( run in 0.598 second using v1.01-cache-2.11-cpan-39bf76dae61 )