function modify_request in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/guzzlehttp/psr7/src/functions.php \GuzzleHttp\Psr7\modify_request()
Clone and modify a request with the given changes.
The changes can be one of:
- method: (string) Changes the HTTP method.
- set_headers: (array) Sets the given headers.
- remove_headers: (array) Remove the given headers.
- body: (mixed) Sets the given body.
- uri: (UriInterface) Set the URI.
- query: (string) Set the query string value of the URI.
- version: (string) Set the protocol version.
Parameters
RequestInterface $request Request to clone and modify.:
array $changes Changes to apply.:
Return value
File
- vendor/
guzzlehttp/ psr7/ src/ functions.php, line 198
Namespace
GuzzleHttp\Psr7Code
function modify_request(RequestInterface $request, array $changes) {
if (!$changes) {
return $request;
}
$headers = $request
->getHeaders();
if (!isset($changes['uri'])) {
$uri = $request
->getUri();
}
else {
// Remove the host header if one is on the URI
if ($host = $changes['uri']
->getHost()) {
$changes['set_headers']['Host'] = $host;
}
$uri = $changes['uri'];
}
if (!empty($changes['remove_headers'])) {
$headers = _caseless_remove($changes['remove_headers'], $headers);
}
if (!empty($changes['set_headers'])) {
$headers = _caseless_remove(array_keys($changes['set_headers']), $headers);
$headers = $changes['set_headers'] + $headers;
}
if (isset($changes['query'])) {
$uri = $uri
->withQuery($changes['query']);
}
return new Request(isset($changes['method']) ? $changes['method'] : $request
->getMethod(), $uri, $headers, isset($changes['body']) ? $changes['body'] : $request
->getBody(), isset($changes['version']) ? $changes['version'] : $request
->getProtocolVersion());
}