Skip to content

Commit 92a8bb9

Browse files
authored
Merge pull request #31 from mickeyn/master
support PATCH HTTP method
2 parents d6fea24 + d92fd70 commit 92a8bb9

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

lib/HTTP/Request.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ This constructs a new request object by parsing the given string.
185185
=item $r->method( $val )
186186
187187
This is used to get/set the method attribute. The method should be a
188-
short string like "GET", "HEAD", "PUT" or "POST".
188+
short string like "GET", "HEAD", "PUT", "PATCH" or "POST".
189189
190190
=item $r->uri
191191

lib/HTTP/Request/Common.pm

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ our $DYNAMIC_FILE_UPLOAD ||= 0; # make it defined (don't know why)
77

88
use Exporter 5.57 'import';
99

10-
our @EXPORT =qw(GET HEAD PUT POST);
10+
our @EXPORT =qw(GET HEAD PUT PATCH POST);
1111
our @EXPORT_OK = qw($DYNAMIC_FILE_UPLOAD DELETE);
1212

1313
require HTTP::Request;
@@ -21,7 +21,7 @@ sub GET { _simple_req('GET', @_); }
2121
sub HEAD { _simple_req('HEAD', @_); }
2222
sub DELETE { _simple_req('DELETE', @_); }
2323

24-
for my $type (qw(PUT POST)) {
24+
for my $type (qw(PUT PATCH POST)) {
2525
no strict 'refs';
2626
*{ __PACKAGE__ . "::" . $type } = sub {
2727
return request_type_with_data($type, @_);
@@ -346,8 +346,8 @@ following call
346346
but is less cluttered. What is different is that a header named
347347
C<Content> will initialize the content part of the request instead of
348348
setting a header field. Note that GET requests should normally not
349-
have a content, so this hack makes more sense for the PUT() and POST()
350-
functions described below.
349+
have a content, so this hack makes more sense for the PUT(), PATCH()
350+
and POST() functions described below.
351351
352352
The get(...) method of C<LWP::UserAgent> exists as a shortcut for
353353
$ua->request(GET ...).
@@ -375,6 +375,14 @@ there is no way to directly specify a header that is actually called
375375
"Content". If you really need this you must update the request
376376
returned in a separate statement.
377377
378+
=item PATCH $url
379+
380+
=item PATCH $url, Header => Value,...
381+
382+
=item PATCH $url, Header => Value,..., Content => $content
383+
384+
Like PUT() but the method in the request is "PATCH".
385+
378386
=item DELETE $url
379387
380388
=item DELETE $url, Header => Value,...

t/common-req.t

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use strict;
22
use warnings;
33

44
use Test::More;
5-
plan tests => 59;
5+
plan tests => 61;
66

77
use HTTP::Request::Common;
88

@@ -40,6 +40,10 @@ $r = PUT "http://www.sn.no",
4040
{ foo => "bar" };
4141
is($r->content, "foo=bar");
4242

43+
$r = PATCH "http://www.sn.no",
44+
{ foo => "bar" };
45+
is($r->content, "foo=bar");
46+
4347
#--- Test POST requests ---
4448

4549
$r = POST "http://www.sn.no", [foo => 'bar;baz',
@@ -233,3 +237,9 @@ $r = HTTP::Request::Common::PUT 'http://www.example.com',
233237
'Content' => 'foobarbaz',
234238
'Content-Length' => 12; # a slight lie
235239
is($r->header('Content-Length'), 9);
240+
241+
$r = HTTP::Request::Common::PATCH 'http://www.example.com',
242+
'Content-Type' => 'application/octet-steam',
243+
'Content' => 'foobarbaz',
244+
'Content-Length' => 12; # a slight lie
245+
is($r->header('Content-Length'), 9);

0 commit comments

Comments
 (0)