forked from leftypol/leftypol
HttpDriver.php: add headers to requestGet
This commit is contained in:
parent
a5cc1c2b42
commit
bf42570d5d
1 changed files with 5 additions and 1 deletions
|
@ -38,11 +38,12 @@ class HttpDriver {
|
|||
*
|
||||
* @param string $endpoint Uri endpoint.
|
||||
* @param ?array $data Optional GET parameters.
|
||||
* @param ?array $data Optional HTTP headers.
|
||||
* @param int $timeout Optional request timeout in seconds. Use the default timeout if 0.
|
||||
* @return string Returns the body of the response.
|
||||
* @throws RuntimeException Throws on IO error.
|
||||
*/
|
||||
public function requestGet(string $endpoint, ?array $data, int $timeout = 0): string {
|
||||
public function requestGet(string $endpoint, ?array $data, ?array $headers, int $timeout = 0): string {
|
||||
if (!empty($data)) {
|
||||
$endpoint .= '?' . \http_build_query($data);
|
||||
}
|
||||
|
@ -51,6 +52,9 @@ class HttpDriver {
|
|||
}
|
||||
|
||||
$this->resetTowards($endpoint, $timeout);
|
||||
if (!empty($headers)) {
|
||||
\curl_setopt($this->inner, \CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
\curl_setopt($this->inner, \CURLOPT_RETURNTRANSFER, true);
|
||||
$ret = \curl_exec($this->inner);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue