Path: blob/trunk/third_party/closure/goog/net/httpstatus.js
2868 views
// Copyright 2011 The Closure Library Authors. All Rights Reserved.1//2// Licensed under the Apache License, Version 2.0 (the "License");3// you may not use this file except in compliance with the License.4// You may obtain a copy of the License at5//6// http://www.apache.org/licenses/LICENSE-2.07//8// Unless required by applicable law or agreed to in writing, software9// distributed under the License is distributed on an "AS-IS" BASIS,10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.11// See the License for the specific language governing permissions and12// limitations under the License.1314/**15* @fileoverview Constants for HTTP status codes.16*/1718goog.provide('goog.net.HttpStatus');192021/**22* HTTP Status Codes defined in RFC 2616 and RFC 6585.23* @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html24* @see http://tools.ietf.org/html/rfc658525* @enum {number}26*/27goog.net.HttpStatus = {28// Informational 1xx29CONTINUE: 100,30SWITCHING_PROTOCOLS: 101,3132// Successful 2xx33OK: 200,34CREATED: 201,35ACCEPTED: 202,36NON_AUTHORITATIVE_INFORMATION: 203,37NO_CONTENT: 204,38RESET_CONTENT: 205,39PARTIAL_CONTENT: 206,4041// Redirection 3xx42MULTIPLE_CHOICES: 300,43MOVED_PERMANENTLY: 301,44FOUND: 302,45SEE_OTHER: 303,46NOT_MODIFIED: 304,47USE_PROXY: 305,48TEMPORARY_REDIRECT: 307,4950// Client Error 4xx51BAD_REQUEST: 400,52UNAUTHORIZED: 401,53PAYMENT_REQUIRED: 402,54FORBIDDEN: 403,55NOT_FOUND: 404,56METHOD_NOT_ALLOWED: 405,57NOT_ACCEPTABLE: 406,58PROXY_AUTHENTICATION_REQUIRED: 407,59REQUEST_TIMEOUT: 408,60CONFLICT: 409,61GONE: 410,62LENGTH_REQUIRED: 411,63PRECONDITION_FAILED: 412,64REQUEST_ENTITY_TOO_LARGE: 413,65REQUEST_URI_TOO_LONG: 414,66UNSUPPORTED_MEDIA_TYPE: 415,67REQUEST_RANGE_NOT_SATISFIABLE: 416,68EXPECTATION_FAILED: 417,69PRECONDITION_REQUIRED: 428,70TOO_MANY_REQUESTS: 429,71REQUEST_HEADER_FIELDS_TOO_LARGE: 431,7273// Server Error 5xx74INTERNAL_SERVER_ERROR: 500,75NOT_IMPLEMENTED: 501,76BAD_GATEWAY: 502,77SERVICE_UNAVAILABLE: 503,78GATEWAY_TIMEOUT: 504,79HTTP_VERSION_NOT_SUPPORTED: 505,80NETWORK_AUTHENTICATION_REQUIRED: 511,8182/*83* IE returns this code for 204 due to its use of URLMon, which returns this84* code for 'Operation Aborted'. The status text is 'Unknown', the response85* headers are ''. Known to occur on IE 6 on XP through IE9 on Win7.86*/87QUIRK_IE_NO_CONTENT: 122388};899091/**92* Returns whether the given status should be considered successful.93*94* Successful codes are OK (200), CREATED (201), ACCEPTED (202),95* NO CONTENT (204), PARTIAL CONTENT (206), NOT MODIFIED (304),96* and IE's no content code (1223).97*98* @param {number} status The status code to test.99* @return {boolean} Whether the status code should be considered successful.100*/101goog.net.HttpStatus.isSuccess = function(status) {102switch (status) {103case goog.net.HttpStatus.OK:104case goog.net.HttpStatus.CREATED:105case goog.net.HttpStatus.ACCEPTED:106case goog.net.HttpStatus.NO_CONTENT:107case goog.net.HttpStatus.PARTIAL_CONTENT:108case goog.net.HttpStatus.NOT_MODIFIED:109case goog.net.HttpStatus.QUIRK_IE_NO_CONTENT:110return true;111112default:113return false;114}115};116117118