Skip to content

Commit

Permalink
use body with 'PUT' method for long URL query string
Browse files Browse the repository at this point in the history
Signed-off-by: Ji-Hyeon Gim <potatogim@gluesys.com>
  • Loading branch information
potatogim committed Mar 22, 2018
1 parent 2816fb6 commit 0d2d1ce
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions lib/Etcd.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,38 @@ sub _build__url_base {
}

sub _prep_url {
my ($self, $path, %args) = @_;
my ($self, $method, $path, %args) = @_;
my $trailing = $path =~ m{/$};
my $url = $self->_url_base.join('/', map { uri_escape($_) } split('/', $path));
$url .= '/' if $trailing;
delete($args{value}) if (uc($method) eq 'PUT');
$url .= '?'.$self->http->www_form_urlencode(\%args) if %args;
$url;
}

sub api_exec {
my ($self, $path, $method, %args) = @_;
my $res = $self->http->request($method, $self->_prep_url($path, %args));

my $urlencoded;

$urlencoded = $self->http->www_form_urlencode({ value => $args{value} })
if (uc($method) eq 'PUT');

my $res = $self->http->request(
$method,
$self->_prep_url($method, $path, %args),
(uc($method) eq 'PUT'
? {
headers => {
'content-length' => length($urlencoded),
'content-type' => 'application/x-www-form-urlencoded',
'expect' => '100-continue',
},
content => $urlencoded
}
: {})
);

$res = $self->http->request($method, $res->{headers}->{location})
if $res && $res->{status} eq 307;
return $res if $res->{success};
Expand Down

0 comments on commit 0d2d1ce

Please sign in to comment.