set content-legth to 0 for vmware vcsa

This commit is contained in:
garnier-quentin 2019-09-03 09:21:41 +02:00
parent b842ec970e
commit f8d7de7ce3
3 changed files with 18 additions and 10 deletions

View File

@ -166,14 +166,15 @@ sub authenticate {
my $has_cache_file = $options{statefile}->read(statefile => 'vcsa_api_' . md5_hex($self->{option_results}->{hostname}) . '_' . md5_hex($self->{option_results}->{api_username}));
my $session_id = $options{statefile}->get(name => 'session_id');
if ($has_cache_file == 0 || !defined($session_id)) {
if ($has_cache_file == 0 || !defined($session_id)) {
my $content = $self->{http}->request(
method => 'POST',
url_path => '/rest/com/vmware/cis/session',
credentials => 1, basic => 1,
username => $self->{api_username},
password => $self->{api_password},
warning_status => '', unknown_status => '', critical_status => ''
warning_status => '', unknown_status => '', critical_status => '',
curl_backend_options => { header => ['Content-Length: 0'] },
);
if ($self->{http}->get_code() != 200) {
$self->{output}->add_option_msg(short_msg => "Login error [code: '" . $self->{http}->get_code() . "'] [message: '" . $self->{http}->get_message() . "']");

View File

@ -131,7 +131,7 @@ sub cb_debug {
if ($type == $uservar->{constant_cb}->(name => 'CURLINFO_SSL_DATA_IN')) {
$msg = sprintf("=> Recv SSL data: %s", $data);
}
$uservar->{output}->output_add(long_msg => $msg, debug => 1);
return 0;
}
@ -313,9 +313,9 @@ sub request {
$content_type_forced = 1;
}
}
$self->set_method(%options, content_type_forced => $content_type_forced, headers => $headers);
if (scalar(@$headers) > 0) {
$self->{curl_easy}->pushopt($self->{constant_cb}->(name => 'CURLOPT_HTTPHEADER'), $headers);
}
@ -341,7 +341,7 @@ sub request {
$self->{output}->add_option_msg(short_msg => 'curl perform error : ' . $@);
$self->{output}->option_exit();
}
$self->{response_code} = $self->{curl_easy}->getinfo($self->{constant_cb}->(name => 'CURLINFO_RESPONSE_CODE'));
# Check response

View File

@ -30,10 +30,10 @@ sub new {
if (!defined($options{noptions}) || $options{noptions} != 1) {
$options{options}->add_options(arguments => {
"http-peer-addr:s" => { name => 'http_peer_addr' },
"proxyurl:s" => { name => 'proxyurl' },
"proxypac:s" => { name => 'proxypac' },
"http-backend:s" => { name => 'http_backend', default => 'lwp' },
'http-peer-addr:s' => { name => 'http_peer_addr' },
'proxyurl:s' => { name => 'proxyurl' },
'proxypac:s' => { name => 'proxypac' },
'http-backend:s' => { name => 'http_backend', default => 'lwp' },
});
$options{options}->add_help(package => __PACKAGE__, sections => 'HTTP GLOBAL OPTIONS');
}
@ -87,6 +87,13 @@ sub check_options {
$self->{output}->option_exit();
}
if (defined($options{request}->{curl_backend_options}) &&
$self->{http_backend} eq 'curl') {
foreach (keys %{$options{request}->{curl_backend_options}}) {
$options{request}->{$_} = $options{request}->{curl_backend_options}->{$_};
}
}
if (($options{request}->{proto} ne 'http') && ($options{request}->{proto} ne 'https')) {
$self->{output}->add_option_msg(short_msg => "Unsupported protocol specified '" . $self->{option_results}->{proto} . "'.");
$self->{output}->option_exit();