Skip to content

Commit

Permalink
http response: ensuring that the repeated response header is merged i…
Browse files Browse the repository at this point in the history
…nto a concatenated string, instead of an array, refs #48
  • Loading branch information
janreges committed Jan 22, 2025
1 parent c8f2ffc commit c0f3b21
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Crawler/HttpClient/HttpResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(string $url, int $statusCode, ?string $body, array $
$this->url = $url;
$this->statusCode = $statusCode;
$this->body = $body;
$this->headers = $headers;
$this->headers = Utils::getFlatResponseHeaders($headers);
$this->execTime = $execTime;
}

Expand Down
17 changes: 17 additions & 0 deletions src/Crawler/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1317,4 +1317,21 @@ public static function isAssetByContentType(string $contentType): bool
return $result;
}

/**
* Get flat response headers (all values are literals, not arrays)
* @param array $headers
* @return array
*/
public static function getFlatResponseHeaders(array $headers): array
{
$result = [];
foreach ($headers as $key => $value) {
if (is_array($value)) {
$value = implode(', ', $value);
}
$result[$key] = $value;
}
return $result;
}

}

0 comments on commit c0f3b21

Please sign in to comment.