/** * Do the HTTP request * * @access public * @return array HTTP response ['body' => ..., 'status' => ..., 'headers' => ...] */ public function doRequest() { $body = ''; // Create context $context = stream_context_create($this->prepareContext()); // Make HTTP request $stream = @fopen($this->url, 'r', false, $context); if (!is_resource($stream)) { throw new InvalidUrlException('Unable to establish a connection'); } // Get HTTP headers response $metadata = stream_get_meta_data($stream); list($status, $headers) = HttpHeaders::parse($metadata['wrapper_data']); if ($this->isPassthroughEnabled()) { header(':', true, $status); if (isset($headers['Content-Type'])) { header('Content-Type: ' . $headers['Content-Type']); } fpassthru($stream); } else { // Get the entire body until the max size $body = stream_get_contents($stream, $this->max_body_size + 1); // If the body size is too large abort everything if (strlen($body) > $this->max_body_size) { throw new MaxSizeException('Content size too large'); } if ($metadata['timed_out']) { throw new TimeoutException('Operation timeout'); } } fclose($stream); $this->setEffectiveUrl($metadata['wrapper_data']); return array('status' => $status, 'body' => $this->decodeBody($body, $headers), 'headers' => $headers); }
/** * Do the HTTP request. * * @return array HTTP response ['body' => ..., 'status' => ..., 'headers' => ...] */ public function doRequest() { $this->executeContext(); list($status, $headers) = HttpHeaders::parse(explode("\n", $this->response_headers[$this->response_headers_count - 1])); if ($this->isRedirection($status)) { return $this->handleRedirection($headers['Location']); } return array('status' => $status, 'body' => $this->body, 'headers' => $headers); }
/** * Do the HTTP request * * @access public * @param bool $follow_location Flag used when there is an open_basedir restriction * @return array HTTP response ['body' => ..., 'status' => ..., 'headers' => ...] */ public function doRequest($follow_location = true) { $this->executeContext(); list($status, $headers) = HttpHeaders::parse(explode("\r\n", $this->headers[$this->headers_counter - 1])); // When restricted with open_basedir if ($this->needToHandleRedirection($follow_location, $status)) { return $this->handleRedirection($headers['Location']); } return array('status' => $status, 'body' => $this->body, 'headers' => $headers); }