Skip to content

Commit

Permalink
RestApi: Do not set body for GET requests
Browse files Browse the repository at this point in the history
  • Loading branch information
raviks789 authored and nilmerg committed Jan 30, 2025
1 parent 42e6fa4 commit 489814d
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions library/Jira/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,19 @@ public function urlLink($url)
protected function request($method, $url, $body = null)
{
$auth = \sprintf('%s:%s', $this->username, $this->password);

$opts = [
CURLOPT_URL => $this->url($url),
CURLOPT_USERPWD => $auth,
CURLOPT_CUSTOMREQUEST => \strtoupper($method),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 3,

// TODO: Fix this!
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false
];

$headers = [
'User-Agent: IcingaWeb2-Jira/v1.0',
];
Expand All @@ -430,23 +443,12 @@ protected function request($method, $url, $body = null)
if ($body !== null) {
$body = \json_encode($body);
$headers[] = 'Content-Length: ' . strlen($body);
$opts[CURLOPT_POSTFIELDS] = $body;
}
$headers[] = 'Content-Type: application/json';
$opts[CURLOPT_HTTPHEADER] = $headers;

$curl = $this->curl();
$opts = array(
CURLOPT_URL => $this->url($url),
CURLOPT_HTTPHEADER => $headers,
CURLOPT_USERPWD => $auth,
CURLOPT_CUSTOMREQUEST => \strtoupper($method),
CURLOPT_POSTFIELDS => $body,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 3,

// TODO: Fix this!
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
);

curl_setopt_array($curl, $opts);
// TODO: request headers, validate status code
Expand Down Expand Up @@ -492,13 +494,12 @@ protected function request($method, $url, $body = null)

/**
* @param $url
* @param null $body
* @return RestApiResponse
* @throws NotFoundError
*/
public function get($url, $body = null)
public function get($url)
{
return $this->request('get', $url, $body);
return $this->request('get', $url);
}

/**
Expand Down

0 comments on commit 489814d

Please sign in to comment.