Requests_Response

HTTP response class.

Defined (1)

The class is defined in the following location(s).

/wp-includes/Requests/Response.php  
  1. class Requests_Response { 
  2. /** 
  3. * Constructor 
  4. */ 
  5. public function __construct() { 
  6. $this->headers = new Requests_Response_Headers(); 
  7. $this->cookies = new Requests_Cookie_Jar(); 
  8.  
  9. /** 
  10. * Response body 
  11. * @var string 
  12. */ 
  13. public $body = ''; 
  14.  
  15. /** 
  16. * Raw HTTP data from the transport 
  17. * @var string 
  18. */ 
  19. public $raw = ''; 
  20.  
  21. /** 
  22. * Headers, as an associative array 
  23. * @var Requests_Response_Headers Array-like object representing headers 
  24. */ 
  25. public $headers = array(); 
  26.  
  27. /** 
  28. * Status code, false if non-blocking 
  29. * @var integer|boolean 
  30. */ 
  31. public $status_code = false; 
  32.  
  33. /** 
  34. * Protocol version, false if non-blocking 
  35. * @var float|boolean 
  36. */ 
  37. public $protocol_version = false; 
  38.  
  39. /** 
  40. * Whether the request succeeded or not 
  41. * @var boolean 
  42. */ 
  43. public $success = false; 
  44.  
  45. /** 
  46. * Number of redirects the request used 
  47. * @var integer 
  48. */ 
  49. public $redirects = 0; 
  50.  
  51. /** 
  52. * URL requested 
  53. * @var string 
  54. */ 
  55. public $url = ''; 
  56.  
  57. /** 
  58. * Previous requests (from redirects) 
  59. * @var array Array of Requests_Response objects 
  60. */ 
  61. public $history = array(); 
  62.  
  63. /** 
  64. * Cookies from the request 
  65. * @var Requests_Cookie_Jar Array-like object representing a cookie jar 
  66. */ 
  67. public $cookies = array(); 
  68.  
  69. /** 
  70. * Is the response a redirect? 
  71. * @return boolean True if redirect (3xx status), false if not. 
  72. */ 
  73. public function is_redirect() { 
  74. $code = $this->status_code; 
  75. return in_array($code, array(300, 301, 302, 303, 307)) || $code > 307 && $code < 400; 
  76.  
  77. /** 
  78. * 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 
  82. */ 
  83. public function throw_for_status($allow_redirects = true) { 
  84. if ($this->is_redirect()) { 
  85. if (!$allow_redirects) { 
  86. throw new Requests_Exception('Redirection not allowed', 'response.no_redirects', $this); 
  87. elseif (!$this->success) { 
  88. $exception = Requests_Exception_HTTP::get_class($this->status_code); 
  89. throw new $exception(null, $this);