Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use HTTP body with 'PUT' method for long URL query string #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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