diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-11-04 21:33:05 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-11-04 21:33:05 -0500 |
commit | 135b921db75da5995eab7e36393ecd4d2b0bc66f (patch) | |
tree | 46efc60fcf1f9d5c57ab1fb9418c2acfbda0698a /vendor/OAuth/Common/Http/Client/StreamClient.php | |
parent | 850645dd6b22f5b495d1680e0b49540e0ebf9bd3 (diff) |
Switch to composer
Diffstat (limited to 'vendor/OAuth/Common/Http/Client/StreamClient.php')
-rwxr-xr-x | vendor/OAuth/Common/Http/Client/StreamClient.php | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/vendor/OAuth/Common/Http/Client/StreamClient.php b/vendor/OAuth/Common/Http/Client/StreamClient.php deleted file mode 100755 index 7f3c5249..00000000 --- a/vendor/OAuth/Common/Http/Client/StreamClient.php +++ /dev/null @@ -1,92 +0,0 @@ -<?php - -namespace OAuth\Common\Http\Client; - -use OAuth\Common\Http\Exception\TokenResponseException; -use OAuth\Common\Http\Uri\UriInterface; - -/** - * Client implementation for streams/file_get_contents - */ -class StreamClient extends AbstractClient -{ - /** - * Any implementing HTTP providers should send a request to the provided endpoint with the parameters. - * They should return, in string form, the response body and throw an exception on error. - * - * @param UriInterface $endpoint - * @param mixed $requestBody - * @param array $extraHeaders - * @param string $method - * - * @return string - * - * @throws TokenResponseException - * @throws \InvalidArgumentException - */ - public function retrieveResponse( - UriInterface $endpoint, - $requestBody, - array $extraHeaders = array(), - $method = 'POST' - ) { - // Normalize method name - $method = strtoupper($method); - - $this->normalizeHeaders($extraHeaders); - - if ($method === 'GET' && !empty($requestBody)) { - throw new \InvalidArgumentException('No body expected for "GET" request.'); - } - - if (!isset($extraHeaders['Content-Type']) && $method === 'POST' && is_array($requestBody)) { - $extraHeaders['Content-Type'] = 'Content-Type: application/x-www-form-urlencoded'; - } - - $host = 'Host: '.$endpoint->getHost(); - // Append port to Host if it has been specified - if ($endpoint->hasExplicitPortSpecified()) { - $host .= ':'.$endpoint->getPort(); - } - - $extraHeaders['Host'] = $host; - $extraHeaders['Connection'] = 'Connection: close'; - - if (is_array($requestBody)) { - $requestBody = http_build_query($requestBody, '', '&'); - } - $extraHeaders['Content-length'] = 'Content-length: '.strlen($requestBody); - - $context = $this->generateStreamContext($requestBody, $extraHeaders, $method); - - $level = error_reporting(0); - $response = file_get_contents($endpoint->getAbsoluteUri(), false, $context); - error_reporting($level); - if (false === $response) { - $lastError = error_get_last(); - if (is_null($lastError)) { - throw new TokenResponseException('Failed to request resource.'); - } - throw new TokenResponseException($lastError['message']); - } - - return $response; - } - - private function generateStreamContext($body, $headers, $method) - { - return stream_context_create( - array( - 'http' => array( - 'method' => $method, - 'header' => implode("\r\n", array_values($headers)), - 'content' => $body, - 'protocol_version' => '1.1', - 'user_agent' => $this->userAgent, - 'max_redirects' => $this->maxRedirects, - 'timeout' => $this->timeout - ), - ) - ); - } -} |