httpstatus.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright 2011 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Constants for HTTP status codes.
  16. */
  17. goog.provide('goog.net.HttpStatus');
  18. /**
  19. * HTTP Status Codes defined in RFC 2616 and RFC 6585.
  20. * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
  21. * @see http://tools.ietf.org/html/rfc6585
  22. * @enum {number}
  23. */
  24. goog.net.HttpStatus = {
  25. // Informational 1xx
  26. CONTINUE: 100,
  27. SWITCHING_PROTOCOLS: 101,
  28. // Successful 2xx
  29. OK: 200,
  30. CREATED: 201,
  31. ACCEPTED: 202,
  32. NON_AUTHORITATIVE_INFORMATION: 203,
  33. NO_CONTENT: 204,
  34. RESET_CONTENT: 205,
  35. PARTIAL_CONTENT: 206,
  36. // Redirection 3xx
  37. MULTIPLE_CHOICES: 300,
  38. MOVED_PERMANENTLY: 301,
  39. FOUND: 302,
  40. SEE_OTHER: 303,
  41. NOT_MODIFIED: 304,
  42. USE_PROXY: 305,
  43. TEMPORARY_REDIRECT: 307,
  44. // Client Error 4xx
  45. BAD_REQUEST: 400,
  46. UNAUTHORIZED: 401,
  47. PAYMENT_REQUIRED: 402,
  48. FORBIDDEN: 403,
  49. NOT_FOUND: 404,
  50. METHOD_NOT_ALLOWED: 405,
  51. NOT_ACCEPTABLE: 406,
  52. PROXY_AUTHENTICATION_REQUIRED: 407,
  53. REQUEST_TIMEOUT: 408,
  54. CONFLICT: 409,
  55. GONE: 410,
  56. LENGTH_REQUIRED: 411,
  57. PRECONDITION_FAILED: 412,
  58. REQUEST_ENTITY_TOO_LARGE: 413,
  59. REQUEST_URI_TOO_LONG: 414,
  60. UNSUPPORTED_MEDIA_TYPE: 415,
  61. REQUEST_RANGE_NOT_SATISFIABLE: 416,
  62. EXPECTATION_FAILED: 417,
  63. PRECONDITION_REQUIRED: 428,
  64. TOO_MANY_REQUESTS: 429,
  65. REQUEST_HEADER_FIELDS_TOO_LARGE: 431,
  66. // Server Error 5xx
  67. INTERNAL_SERVER_ERROR: 500,
  68. NOT_IMPLEMENTED: 501,
  69. BAD_GATEWAY: 502,
  70. SERVICE_UNAVAILABLE: 503,
  71. GATEWAY_TIMEOUT: 504,
  72. HTTP_VERSION_NOT_SUPPORTED: 505,
  73. NETWORK_AUTHENTICATION_REQUIRED: 511,
  74. /*
  75. * IE returns this code for 204 due to its use of URLMon, which returns this
  76. * code for 'Operation Aborted'. The status text is 'Unknown', the response
  77. * headers are ''. Known to occur on IE 6 on XP through IE9 on Win7.
  78. */
  79. QUIRK_IE_NO_CONTENT: 1223
  80. };
  81. /**
  82. * Returns whether the given status should be considered successful.
  83. *
  84. * Successful codes are OK (200), CREATED (201), ACCEPTED (202),
  85. * NO CONTENT (204), PARTIAL CONTENT (206), NOT MODIFIED (304),
  86. * and IE's no content code (1223).
  87. *
  88. * @param {number} status The status code to test.
  89. * @return {boolean} Whether the status code should be considered successful.
  90. */
  91. goog.net.HttpStatus.isSuccess = function(status) {
  92. switch (status) {
  93. case goog.net.HttpStatus.OK:
  94. case goog.net.HttpStatus.CREATED:
  95. case goog.net.HttpStatus.ACCEPTED:
  96. case goog.net.HttpStatus.NO_CONTENT:
  97. case goog.net.HttpStatus.PARTIAL_CONTENT:
  98. case goog.net.HttpStatus.NOT_MODIFIED:
  99. case goog.net.HttpStatus.QUIRK_IE_NO_CONTENT:
  100. return true;
  101. default:
  102. return false;
  103. }
  104. };