5 * Contains a response from Requests::request()
12 * Contains a response from Requests::request()
15 class Requests_Response {
19 public function __construct() {
20 $this->headers = new Requests_Response_Headers();
30 * Raw HTTP data from the transport
36 * Headers, as an associative array
39 public $headers = array();
42 * Status code, false if non-blocking
43 * @var integer|boolean
45 public $status_code = false;
48 * Whether the request succeeded or not
51 public $success = false;
54 * Number of redirects the request used
57 public $redirects = 0;
66 * Previous requests (from redirects)
67 * @var array Array of Requests_Response objects
69 public $history = array();
72 * Cookies from the request
74 public $cookies = array();
77 * Throws an exception if the request was not successful
79 * @throws Requests_Exception If `$allow_redirects` is false, and code is 3xx (`response.no_redirects`)
80 * @throws Requests_Exception_HTTP On non-successful status code. Exception class corresponds to code (e.g. {@see Requests_Exception_HTTP_404})
81 * @param boolean $allow_redirects Set to false to throw on a 3xx as well
83 public function throw_for_status($allow_redirects = true) {
84 if ($this->status_code >= 300 && $this->status_code < 400) {
85 if (!$allow_redirects) {
86 throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this);
90 elseif (!$this->success) {
91 $exception = Requests_Exception_HTTP::get_class($this->status_code);
92 throw new $exception(null, $this);