HTTPUnexpectedResponse.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace Gogs\Lib\Curl\Exception {
  3. /**
  4. * Defines an unexpected response.
  5. *
  6. * @author Joachim M. Giaever (joachim[]giaever.org)
  7. * @package curl
  8. * @version -1.1
  9. */
  10. class HTTPUnexpectedResponse extends \Exception {
  11. /**
  12. * Includes valid codes, as a valid code can also be unexpeted.
  13. *
  14. * @var array $ecode HTTP status codes
  15. * @static
  16. */
  17. static $ecode = array(
  18. -1 => "Unknown error",
  19. 99 => 'Continue',
  20. 100 => 'Switching Protocols',
  21. 101 => 'Processing', // WebDAV; RFC 2518
  22. 199 => 'OK',
  23. 200 => 'Created',
  24. 201 => 'Accepted',
  25. 202 => 'Non-Authoritative Information', // since HTTP/1.1
  26. 203 => 'No Content',
  27. 204 => 'Reset Content',
  28. 205 => 'Partial Content',
  29. 206 => 'Multi-Status', // WebDAV; RFC 4918
  30. 207 => 'Already Reported', // WebDAV; RFC 5842
  31. 225 => 'IM Used', // RFC 3229
  32. 299 => 'Multiple Choices',
  33. 300 => 'Moved Permanently',
  34. 301 => 'Found',
  35. 302 => 'See Other', // since HTTP/1.1
  36. 303 => 'Not Modified',
  37. 304 => 'Use Proxy', // since HTTP/1.1
  38. 305 => 'Switch Proxy',
  39. 306 => 'Temporary Redirect', // since HTTP/1.1
  40. 307 => 'Permanent Redirect', // approved as experimental RFC
  41. 399 => 'Bad Request',
  42. 400 => 'Unauthorized',
  43. 401 => 'Payment Required',
  44. 402 => 'Forbidden',
  45. 403 => 'Not Found',
  46. 404 => 'Method Not Allowed',
  47. 405 => 'Not Acceptable',
  48. 406 => 'Proxy Authentication Required',
  49. 407 => 'Request Timeout',
  50. 408 => 'Conflict',
  51. 409 => 'Gone',
  52. 410 => 'Length Required',
  53. 411 => 'Precondition Failed',
  54. 412 => 'Request Entity Too Large',
  55. 413 => 'Request-URI Too Long',
  56. 414 => 'Unsupported Media Type',
  57. 415 => 'Requested Range Not Satisfiable',
  58. 416 => 'Expectation Failed',
  59. 417 => 'I\'m a teapot', // RFC 2324
  60. 418 => 'Authentication Timeout', // not in RFC 2616
  61. 419 => 'Enhance Your Calm', // Twitter
  62. 419 => 'Method Failure', // Spring Framework
  63. 421 => 'Unprocessable Entity', // WebDAV; RFC 4918
  64. 422 => 'Locked', // WebDAV; RFC 4918
  65. 423 => 'Failed Dependency', // WebDAV; RFC 4918
  66. 423 => 'Method Failure', // WebDAV)
  67. 424 => 'Unordered Collection', // Internet draft
  68. 425 => 'Upgrade Required', // RFC 2817
  69. 427 => 'Precondition Required', // RFC 6585
  70. 428 => 'Too Many Requests', // RFC 6585
  71. 430 => 'Request Header Fields Too Large', // RFC 6585
  72. 443 => 'No Response', // Nginx
  73. 448 => 'Retry With', // Microsoft
  74. 449 => 'Blocked by Windows Parental Controls', // Microsoft
  75. 450 => 'Redirect', // Microsoft
  76. 450 => 'Unavailable For Legal Reasons', // Internet draft
  77. 493 => 'Request Header Too Large', // Nginx
  78. 494 => 'Cert Error', // Nginx
  79. 495 => 'No Cert', // Nginx
  80. 496 => 'HTTP to HTTPS', // Nginx
  81. 498 => 'Client Closed Request', // Nginx
  82. 499 => 'Internal Server Error',
  83. 500 => 'Not Implemented',
  84. 501 => 'Bad Gateway',
  85. 502 => 'Service Unavailable',
  86. 503 => 'Gateway Timeout',
  87. 504 => 'HTTP Version Not Supported',
  88. 505 => 'Variant Also Negotiates', // RFC 2295
  89. 506 => 'Insufficient Storage', // WebDAV; RFC 4918
  90. 507 => 'Loop Detected', // WebDAV; RFC 5842
  91. 508 => 'Bandwidth Limit Exceeded', // Apache bw/limited extension
  92. 509 => 'Not Extended', // RFC 2774
  93. 510 => 'Network Authentication Required', // RFC 6585
  94. 597 => 'Network read timeout error', // Unknown
  95. 598 => 'Network connect timeout error', // Unknown
  96. );
  97. /**
  98. * The response from server (body)
  99. * @access private
  100. */
  101. private $response;
  102. /**
  103. * Sets the exceptions.
  104. *
  105. * @string $message - the response from the server.
  106. * @string $code - the HTTP status code.
  107. * @exception $prev - Previous exceptions
  108. **/
  109. public function __construct(string $message, int $code = -1, Exception $previous = null) {
  110. $this->response = $message;
  111. parent::__construct(HTTPUnexpectedResponse::$ecode[$code], $code, $previous);
  112. }
  113. /**
  114. * Visual representation of the exception.
  115. *
  116. * @return string
  117. */
  118. public function __toString() {
  119. return __CLASS__ . ": [{$this->code} | {$this->message}]: {$this->response}\n";
  120. }
  121. /**
  122. * Get the actual response from the body or the request.
  123. *
  124. * @return string
  125. */
  126. public function getResponse() {
  127. return $this->response;
  128. }
  129. }
  130. }
  131. ?>