You are here

private function StreamHandler::getDefaultContext in Auth0 Single Sign On 8.2

1 call to StreamHandler::getDefaultContext()
StreamHandler::createStream in vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php

File

vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php, line 374

Class

StreamHandler
HTTP handler that uses PHP's HTTP stream wrapper.

Namespace

GuzzleHttp\Handler

Code

private function getDefaultContext(RequestInterface $request) {
  $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,
    ],
  ];
  $body = (string) $request
    ->getBody();
  if (!empty($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;
}