From d53e9863aafe93f1e6aa665ece00e81096063c9e Mon Sep 17 00:00:00 2001 From: Rob Landers Date: Mon, 24 May 2021 13:12:21 +0200 Subject: [PATCH] Properly read etags from GET responses (#92) --- src/lib/DaprClient.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/DaprClient.php b/src/lib/DaprClient.php index 92a5d94..7914e82 100644 --- a/src/lib/DaprClient.php +++ b/src/lib/DaprClient.php @@ -52,16 +52,20 @@ public function get(string $url, ?array $params = null): DaprResponse CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => self::get_headers(), CURLINFO_HEADER_OUT => true, + CURLOPT_HEADER => true, ] ); $result = curl_exec($curl); $return = new DaprResponse(); - $return->data = json_decode($result, true); + $header_size = curl_getinfo($curl, CURLINFO_HEADER_SIZE); + $header = substr($result, 0, $header_size); + $body = substr($result, $header_size); + $return->data = json_decode($body, true); $return->code = curl_getinfo($curl, CURLINFO_HTTP_CODE); - $return->headers = explode("\r\n", curl_getinfo($curl, CURLINFO_HEADER_OUT)); + $return->headers = explode("\r\n", $header); $return->etag = array_reduce( $return->headers, - fn($carry, $item) => str_starts_with($item, 'etag:') ? str_replace('etag: ', '', $item) : $carry + fn($carry, $item) => str_starts_with($item, 'Etag:') ? str_replace('Etag: ', '', $item) : $carry ); $this->logger->debug('Got response: {response}', ['response' => $return]);