diff options
Diffstat (limited to 'vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php')
-rw-r--r-- | vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php index 36c5ca6f3..75a0122e2 100644 --- a/vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php +++ b/vendor/fguillot/picofeed/lib/PicoFeed/Client/Stream.php @@ -5,17 +5,15 @@ namespace PicoFeed\Client; use PicoFeed\Logging\Logger; /** - * Stream context HTTP client + * Stream context HTTP client. * * @author Frederic Guillot - * @package Client */ class Stream extends Client { /** - * Prepare HTTP headers + * Prepare HTTP headers. * - * @access private * @return string[] */ private function prepareHeaders() @@ -27,7 +25,7 @@ class Stream extends Client // disable compression in passthrough mode. It could result in double // compressed content which isn't decodeable by browsers - if (function_exists('gzdecode') && ! $this->isPassthroughEnabled()) { + if (function_exists('gzdecode') && !$this->isPassthroughEnabled()) { $headers[] = 'Accept-Encoding: gzip'; } @@ -53,14 +51,13 @@ class Stream extends Client } /** - * Construct the final URL from location headers + * Construct the final URL from location headers. * - * @access private - * @param array $headers List of HTTP response header + * @param array $headers List of HTTP response header */ private function setEffectiveUrl($headers) { - foreach($headers as $header) { + foreach ($headers as $header) { if (stripos($header, 'Location') === 0) { list(, $value) = explode(': ', $header); @@ -70,9 +67,8 @@ class Stream extends Client } /** - * Prepare stream context + * Prepare stream context. * - * @access private * @return array */ private function prepareContext() @@ -83,11 +79,10 @@ class Stream extends Client 'protocol_version' => 1.1, 'timeout' => $this->timeout, 'max_redirects' => $this->max_redirects, - ) + ), ); if ($this->proxy_hostname) { - Logger::setMessage(get_called_class().' Proxy: '.$this->proxy_hostname.':'.$this->proxy_port); $context['http']['proxy'] = 'tcp://'.$this->proxy_hostname.':'.$this->proxy_port; @@ -95,8 +90,7 @@ class Stream extends Client if ($this->proxy_username) { Logger::setMessage(get_called_class().' Proxy credentials: Yes'); - } - else { + } else { Logger::setMessage(get_called_class().' Proxy credentials: No'); } } @@ -107,10 +101,9 @@ class Stream extends Client } /** - * Do the HTTP request + * Do the HTTP request. * - * @access public - * @return array HTTP response ['body' => ..., 'status' => ..., 'headers' => ...] + * @return array HTTP response ['body' => ..., 'status' => ..., 'headers' => ...] */ public function doRequest() { @@ -121,7 +114,7 @@ class Stream extends Client // Make HTTP request $stream = @fopen($this->url, 'r', false, $context); - if (! is_resource($stream)) { + if (!is_resource($stream)) { throw new InvalidUrlException('Unable to establish a connection'); } @@ -137,8 +130,7 @@ class Stream extends Client } fpassthru($stream); - } - else { + } else { // Get the entire body until the max size $body = stream_get_contents($stream, $this->max_body_size + 1); @@ -159,16 +151,16 @@ class Stream extends Client return array( 'status' => $status, 'body' => $this->decodeBody($body, $headers), - 'headers' => $headers + 'headers' => $headers, ); } /** - * Decode body response according to the HTTP headers + * Decode body response according to the HTTP headers. + * + * @param string $body Raw body + * @param HttpHeaders $headers HTTP headers * - * @access public - * @param string $body Raw body - * @param HttpHeaders $headers HTTP headers * @return string */ public function decodeBody($body, HttpHeaders $headers) @@ -178,22 +170,22 @@ class Stream extends Client } if (isset($headers['Content-Encoding']) && $headers['Content-Encoding'] === 'gzip') { - $body = @gzdecode($body); + $body = gzdecode($body); } return $body; } /** - * Decode a chunked body + * Decode a chunked body. + * + * @param string $str Raw body * - * @access public - * @param string $str Raw body - * @return string Decoded body + * @return string Decoded body */ public function decodeChunked($str) { - for ($result = ''; ! empty($str); $str = trim($str)) { + for ($result = ''; !empty($str); $str = trim($str)) { // Get the chunk length $pos = strpos($str, "\r\n"); |