Skip to content

Commit

Permalink
Model: Don't add empty bodies
Browse files Browse the repository at this point in the history
  • Loading branch information
SMillerDev committed Jun 2, 2017
1 parent 1a99b3a commit ea1bdc9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/PHPDraft/Model/HTTPRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,23 @@ public function get_curl_command($base_url, $additional = [])
$type = (isset($this->headers['Content-Type'])) ? $this->headers['Content-Type'] : null;

$options[] = '-X' . $this->method;
if (is_string($this->body)) {
$options[] = '--data-binary "' . $this->body . '"';
if (empty($this->body)){
//NO-OP
}elseif (is_string($this->body)) {
$options[] = '--data-binary ' . escapeshellarg($this->body);
} elseif (is_array($this->body)) {
$options[] = '--data-binary "' . join('', $this->body) . '"';
$options[] = '--data-binary ' . escapeshellarg(join('', $this->body));
} elseif (is_subclass_of($this->struct, StructureElement::class)) {
foreach ($this->struct->value as $body) {
$options[] = '--data-binary "' . strip_tags($body->print_request($type)) . '"';
$options[] = '--data-binary ' . escapeshellarg(strip_tags($body->print_request($type)));
}
}
foreach ($this->headers as $header => $value) {
$options[] = '-H "' . $header . ': ' . $value . '"';
$options[] = '-H ' . escapeshellarg($header . ': ' . $value);
}
$options = array_merge($options, $additional);

return htmlspecialchars('curl ' . join(' ', $options) . ' "' . $this->parent->build_url($base_url, true) . '"');
return htmlspecialchars('curl ' . join(' ', $options) . ' ' . escapeshellarg($this->parent->build_url($base_url, true)));
}


Expand Down

0 comments on commit ea1bdc9

Please sign in to comment.