|
|
@@ -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 = '';
|