=== modified file 'lib/Net/Async/HTTP.pm'
--- lib/Net/Async/HTTP.pm 2014-03-29 19:39:41 +0000
+++ lib/Net/Async/HTTP.pm 2014-10-14 10:03:16 +0000
@@ -466,9 +466,9 @@
=item content => STRING or ARRAY ref
-Optional. The body content to use for C<POST> requests. If this is a plain
-scalar instead of an ARRAY ref, it will not be form encoded. In this case, a
-C<content_type> field must also be supplied to describe it.
+Optional. The body content to use for C<PUT> or C<POST> requests. If this is a
+plain scalar instead of an ARRAY ref, it will not be form encoded. In this
+case, a C<content_type> field must also be supplied to describe it.
=item content_type => STRING
@@ -825,13 +825,19 @@
# Lack of content_type didn't used to be a failure condition:
ref $args{content} or defined $args{content_type} or
- carp "No 'content_type' was given with 'content'";
+ carp "No 'content_type' was given with 'content'";
# This will automatically encode a form for us
$request = HTTP::Request::Common::POST( $uri, Content => $args{content}, Content_Type => $args{content_type} );
}
else {
$request = HTTP::Request->new( $method, $uri );
+ if( defined $args{content} ) {
+ defined $args{content_type} or carp "No 'content_type' was given with 'content'";
+
+ $request->content( $args{content} );
+ $request->content_type( $args{content_type} // "" );
+ }
}
$request->protocol( "HTTP/1.1" );
=== modified file 't/02uri.t'
--- t/02uri.t 2013-10-31 18:33:44 +0000
+++ t/02uri.t 2014-10-14 10:03:16 +0000
@@ -249,28 +249,54 @@
expect_res_content => "Shhhh!",
);
+do_test_uri( "simple PUT",
+ method => "PUT",
+ uri => URI->new( "
http://host5/resource" ),
+ content => "The content",
+ content_type => "text/plain",
+
+ expect_req_firstline => "PUT /resource HTTP/1.1",
+ expect_req_headers => {
+ Host => "host5",
+ 'Content-Length' => 11,
+ 'Content-Type' => "text/plain",
+ },
+ expect_req_content => "The content",
+
+ response => "HTTP/1.1 201 Created$CRLF" .
+ "Content-Length: 0$CRLF" .
+ "Connection: Keep-Alive$CRLF" .
+ $CRLF,
+
+ expect_res_code => 201,
+ expect_res_headers => {
+ 'Content-Length' => 0,
+ 'Connection' => "Keep-Alive",
+ },
+);
+
do_test_uri( "simple POST",
method => "POST",
- uri => URI->new( "
http://host5/handler" ),
+ uri => URI->new( "
http://host6/handler" ),
content => "New content",
content_type => "text/plain",
expect_req_firstline => "POST /handler HTTP/1.1",
expect_req_headers => {
- Host => "host5",
+ Host => "host6",
'Content-Length' => 11,
'Content-Type' => "text/plain",
},
expect_req_content => "New content",
- response => "HTTP/1.1 201 Created$CRLF" .
+ response => "HTTP/1.1 200 OK$CRLF" .
"Content-Length: 11$CRLF" .
"Content-Type: text/plain$CRLF" .
"Connection: Keep-Alive$CRLF" .
$CRLF .
"New content",
- expect_res_code => 201,
+ expect_res_code => 200,
expect_res_headers => {
'Content-Length' => 11,
'Content-Type' => "text/plain",
@@ -281,12 +307,12 @@
do_test_uri( "form POST",
method => "POST",
- uri => URI->new( "
http://host6/handler" ),
+ uri => URI->new( "
http://host7/handler" ),
content => [ param => "value", another => "value with things" ],
expect_req_firstline => "POST /handler HTTP/1.1",
expect_req_headers => {
- Host => "host6",
+ Host => "host7",
'Content-Length' => 37,
'Content-Type' => "application/x-www-form-urlencoded",
},
@@ -310,11 +336,11 @@
do_test_uri( "plain string URI",
method => "GET",
- uri => "
http://host7/path",
+ uri => "
http://host8/path",
expect_req_firstline => "GET /path HTTP/1.1",
expect_req_headers => {
- Host => "host7",
+ Host => "host8",
},
response => "HTTP/1.1 200 OK$CRLF" .