X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fguzzlehttp%2Fguzzle%2Fsrc%2FHandler%2FStreamHandler.php;fp=vendor%2Fguzzlehttp%2Fguzzle%2Fsrc%2FHandler%2FStreamHandler.php;h=b12bfd942398a63b3e6430e227dd05fa482e5a50;hb=3f4e21847e67242d3000b01156783f25594f7333;hp=4972f54a4f7ed4fa2e1846ccb77d1d71b3d28b33;hpb=8acec36f19c470dfcda1ae2336826a782f41874c;p=yaffs-website diff --git a/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php b/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php index 4972f54a4..b12bfd942 100644 --- a/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php +++ b/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php @@ -67,7 +67,7 @@ class StreamHandler $e = RequestException::wrapException($request, $e); $this->invokeStats($options, $request, $startTime, null, $e); - return new RejectedPromise($e); + return \GuzzleHttp\Promise\rejection_for($e); } } @@ -119,7 +119,7 @@ class StreamHandler } catch (\Exception $e) { $msg = 'An error was encountered during the on_headers event'; $ex = new RequestException($msg, $request, $response, $e); - return new RejectedPromise($ex); + return \GuzzleHttp\Promise\rejection_for($ex); } } @@ -301,6 +301,18 @@ class StreamHandler ); } + // Microsoft NTLM authentication only supported with curl handler + if (isset($options['auth']) + && is_array($options['auth']) + && isset($options['auth'][2]) + && 'ntlm' == $options['auth'][2] + ) { + + throw new \InvalidArgumentException('Microsoft NTLM authentication only supported with curl handler'); + } + + $uri = $this->resolveHost($request, $options); + $context = $this->createResource( function () use ($context, $params) { return stream_context_create($context, $params); @@ -308,14 +320,45 @@ class StreamHandler ); return $this->createResource( - function () use ($request, &$http_response_header, $context) { - $resource = fopen((string) $request->getUri()->withFragment(''), 'r', null, $context); + function () use ($uri, &$http_response_header, $context, $options) { + $resource = fopen((string) $uri, 'r', null, $context); $this->lastHeaders = $http_response_header; + + if (isset($options['read_timeout'])) { + $readTimeout = $options['read_timeout']; + $sec = (int) $readTimeout; + $usec = ($readTimeout - $sec) * 100000; + stream_set_timeout($resource, $sec, $usec); + } + return $resource; } ); } + private function resolveHost(RequestInterface $request, array $options) + { + $uri = $request->getUri(); + + if (isset($options['force_ip_resolve']) && !filter_var($uri->getHost(), FILTER_VALIDATE_IP)) { + if ('v4' === $options['force_ip_resolve']) { + $records = dns_get_record($uri->getHost(), DNS_A); + if (!isset($records[0]['ip'])) { + throw new ConnectException(sprintf("Could not resolve IPv4 address for host '%s'", $uri->getHost()), $request); + } + $uri = $uri->withHost($records[0]['ip']); + } elseif ('v6' === $options['force_ip_resolve']) { + $records = dns_get_record($uri->getHost(), DNS_AAAA); + if (!isset($records[0]['ipv6'])) { + throw new ConnectException(sprintf("Could not resolve IPv6 address for host '%s'", $uri->getHost()), $request); + } + $uri = $uri->withHost('[' . $records[0]['ipv6'] . ']'); + } + } + + return $uri; + } + private function getDefaultContext(RequestInterface $request) { $headers = '';