Skip to content

Commit

Permalink
Properly read etags from GET responses (dapr#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
withinboredom authored May 24, 2021
1 parent 8c6dda2 commit d53e986
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/DaprClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down

0 comments on commit d53e986

Please sign in to comment.