Skip to content

Commit 2da8393

Browse files
committed
use body with 'PUT' method for long URL query string
Signed-off-by: Ji-Hyeon Gim <potatogim@gluesys.com>
1 parent 2816fb6 commit 2da8393

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

lib/Etcd.pm

+23-2
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,38 @@ sub _build__url_base {
2929
}
3030

3131
sub _prep_url {
32-
my ($self, $path, %args) = @_;
32+
my ($self, $method, $path, %args) = @_;
3333
my $trailing = $path =~ m{/$};
3434
my $url = $self->_url_base.join('/', map { uri_escape($_) } split('/', $path));
3535
$url .= '/' if $trailing;
36+
delete($args{value}) if (uc($method) eq 'PUT');
3637
$url .= '?'.$self->http->www_form_urlencode(\%args) if %args;
3738
$url;
3839
}
3940

4041
sub api_exec {
4142
my ($self, $path, $method, %args) = @_;
42-
my $res = $self->http->request($method, $self->_prep_url($path, %args));
43+
44+
my $urlencoded;
45+
46+
$urlencoded = $self->http->www_form_urlencode({ value => $args{value} })
47+
if (uc($method) eq 'PUT');
48+
49+
my $res = $self->http->request(
50+
$method,
51+
$self->_prep_url($method, $path, %args),
52+
(uc($method) eq 'PUT' ?
53+
{
54+
headers => {
55+
'content-length' => length($urlencoded),
56+
'content-type' => 'application/x-www-form-urlencoded',
57+
'expect' => '100-continue',
58+
},
59+
content => $urlencoded
60+
} :
61+
undef)
62+
);
63+
4364
$res = $self->http->request($method, $res->{headers}->{location})
4465
if $res && $res->{status} eq 307;
4566
return $res if $res->{success};

0 commit comments

Comments
 (0)