From bf42570d5dada46f281951f56487efba692dc44c Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sun, 16 Mar 2025 22:52:28 +0100 Subject: [PATCH] HttpDriver.php: add headers to requestGet --- inc/Data/Driver/HttpDriver.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/inc/Data/Driver/HttpDriver.php b/inc/Data/Driver/HttpDriver.php index 022fcbab..197f2681 100644 --- a/inc/Data/Driver/HttpDriver.php +++ b/inc/Data/Driver/HttpDriver.php @@ -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);