function StreamHandler::getDefaultContext
1 call to StreamHandler::getDefaultContext()
- StreamHandler::createStream in vendor/
guzzlehttp/ guzzle/ src/ Handler/ StreamHandler.php
File
-
vendor/
guzzlehttp/ guzzle/ src/ Handler/ StreamHandler.php, line 376
Class
- StreamHandler
- HTTP handler that uses PHP's HTTP stream wrapper.
Namespace
GuzzleHttp\HandlerCode
private function getDefaultContext(RequestInterface $request) : array {
$headers = '';
foreach ($request->getHeaders() as $name => $value) {
foreach ($value as $val) {
$headers .= "{$name}: {$val}\r\n";
}
}
$context = [
'http' => [
'method' => $request->getMethod(),
'header' => $headers,
'protocol_version' => $request->getProtocolVersion(),
'ignore_errors' => true,
'follow_location' => 0,
],
'ssl' => [
'peer_name' => $request->getUri()
->getHost(),
],
];
$body = (string) $request->getBody();
if ('' !== $body) {
$context['http']['content'] = $body;
// Prevent the HTTP handler from adding a Content-Type header.
if (!$request->hasHeader('Content-Type')) {
$context['http']['header'] .= "Content-Type:\r\n";
}
}
$context['http']['header'] = \rtrim($context['http']['header']);
return $context;
}