Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/HTTP/Request.pm
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ This constructs a new request object by parsing the given string.
=item $r->method( $val )

This is used to get/set the method attribute. The method should be a
short string like "GET", "HEAD", "PUT" or "POST".
short string like "GET", "HEAD", "PUT", "PATCH" or "POST".

=item $r->uri

Expand Down
16 changes: 12 additions & 4 deletions lib/HTTP/Request/Common.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ our $DYNAMIC_FILE_UPLOAD ||= 0; # make it defined (don't know why)

use Exporter 5.57 'import';

our @EXPORT =qw(GET HEAD PUT POST);
our @EXPORT =qw(GET HEAD PUT PATCH POST);
our @EXPORT_OK = qw($DYNAMIC_FILE_UPLOAD DELETE);

require HTTP::Request;
Expand All @@ -21,7 +21,7 @@ sub GET { _simple_req('GET', @_); }
sub HEAD { _simple_req('HEAD', @_); }
sub DELETE { _simple_req('DELETE', @_); }

for my $type (qw(PUT POST)) {
for my $type (qw(PUT PATCH POST)) {
no strict 'refs';
*{ __PACKAGE__ . "::" . $type } = sub {
return request_type_with_data($type, @_);
Expand Down Expand Up @@ -346,8 +346,8 @@ following call
but is less cluttered. What is different is that a header named
C<Content> will initialize the content part of the request instead of
setting a header field. Note that GET requests should normally not
have a content, so this hack makes more sense for the PUT() and POST()
functions described below.
have a content, so this hack makes more sense for the PUT(), PATCH()
and POST() functions described below.

The get(...) method of C<LWP::UserAgent> exists as a shortcut for
$ua->request(GET ...).
Expand Down Expand Up @@ -375,6 +375,14 @@ there is no way to directly specify a header that is actually called
"Content". If you really need this you must update the request
returned in a separate statement.

=item PATCH $url

=item PATCH $url, Header => Value,...

=item PATCH $url, Header => Value,..., Content => $content

Like PUT() but the method in the request is "PATCH".

=item DELETE $url

=item DELETE $url, Header => Value,...
Expand Down
12 changes: 11 additions & 1 deletion t/common-req.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use strict;
use warnings;

use Test::More;
plan tests => 59;
plan tests => 61;

use HTTP::Request::Common;

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

$r = PATCH "http://www.sn.no",
{ foo => "bar" };
is($r->content, "foo=bar");

#--- Test POST requests ---

$r = POST "http://www.sn.no", [foo => 'bar;baz',
Expand Down Expand Up @@ -233,3 +237,9 @@ $r = HTTP::Request::Common::PUT 'http://www.example.com',
'Content' => 'foobarbaz',
'Content-Length' => 12; # a slight lie
is($r->header('Content-Length'), 9);

$r = HTTP::Request::Common::PATCH 'http://www.example.com',
'Content-Type' => 'application/octet-steam',
'Content' => 'foobarbaz',
'Content-Length' => 12; # a slight lie
is($r->header('Content-Length'), 9);