HttpStatus.class 源码中状态码总结
HttpStatus.class 源码
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package org.springframework.http;
import org.springframework.lang.Nullable;
public enum HttpStatus implements HttpStatusCode {
CONTINUE(100, HttpStatus.Series.INFORMATIONAL, "Continue"),
SWITCHING_PROTOCOLS(101, HttpStatus.Series.INFORMATIONAL, "Switching Protocols"),
PROCESSING(102, HttpStatus.Series.INFORMATIONAL, "Processing"),
EARLY_HINTS(103, HttpStatus.Series.INFORMATIONAL, "Early Hints"),
/** @deprecated */
@Deprecated(
since = "6.0.5"
)
CHECKPOINT(103, HttpStatus.Series.INFORMATIONAL, "Checkpoint"),
OK(200, HttpStatus.Series.SUCCESSFUL, "OK"),
CREATED(201, HttpStatus.Series.SUCCESSFUL, "Created"),
ACCEPTED(202, HttpStatus.Series.SUCCESSFUL, "Accepted"),
NON_AUTHORITATIVE_INFORMATION(203, HttpStatus.Series.SUCCESSFUL, "Non-Authoritative Information"),
NO_CONTENT(204, HttpStatus.Series.SUCCESSFUL, "No Content"),
RESET_CONTENT(205, HttpStatus.Series.SUCCESSFUL, "Reset Content"),
PARTIAL_CONTENT(206, HttpStatus.Series.SUCCESSFUL, "Partial Content"),
MULTI_STATUS(207, HttpStatus.Series.SUCCESSFUL, "Multi-Status"),
ALREADY_REPORTED(208, HttpStatus.Series.SUCCESSFUL, "Already Reported"),
IM_USED(226, HttpStatus.Series.SUCCESSFUL, "IM Used"),
MULTIPLE_CHOICES(300, HttpStatus.Series.REDIRECTION, "Multiple Choices"),
MOVED_PERMANENTLY(301, HttpStatus.Series.REDIRECTION, "Moved Permanently"),
FOUND(302, HttpStatus.Series.REDIRECTION, "Found"),
/** @deprecated */
@Deprecated
MOVED_TEMPORARILY(302, HttpStatus.Series.REDIRECTION, "Moved Temporarily"),
SEE_OTHER(303, HttpStatus.Series.REDIRECTION, "See Other"),
NOT_MODIFIED(304, HttpStatus.Series.REDIRECTION, "Not Modified"),
/** @deprecated */
@Deprecated
USE_PROXY(305, HttpStatus.Series.REDIRECTION, "Use Proxy"),
TEMPORARY_REDIRECT(307, HttpStatus.Series.REDIRECTION, "Temporary Redirect"),
PERMANENT_REDIRECT(308, HttpStatus.Series.REDIRECTION, "Permanent Redirect"),
BAD_REQUEST(400, HttpStatus.Series.CLIENT_ERROR, "Bad Request"),
UNAUTHORIZED(401, HttpStatus.Series.CLIENT_ERROR, "Unauthorized"),
PAYMENT_REQUIRED(402, HttpStatus.Series.CLIENT_ERROR, "Payment Required"),
FORBIDDEN(403, HttpStatus.Series.CLIENT_ERROR, "Forbidden"),
NOT_FOUND(404, HttpStatus.Series.CLIENT_ERROR, "Not Found"),
METHOD_NOT_ALLOWED(405, HttpStatus.Series.CLIENT_ERROR, "Method Not Allowed"),
NOT_ACCEPTABLE(406, HttpStatus.Series.CLIENT_ERROR, "Not Acceptable"),
PROXY_AUTHENTICATION_REQUIRED(407, HttpStatus.Series.CLIENT_ERROR, "Proxy Authentication Required"),
REQUEST_TIMEOUT(408, HttpStatus.Series.CLIENT_ERROR, "Request Timeout"),
CONFLICT(409, HttpStatus.Series.CLIENT_ERROR, "Conflict"),
GONE(410, HttpStatus.Series.CLIENT_ERROR, "Gone"),
LENGTH_REQUIRED(411, HttpStatus.Series.CLIENT_ERROR, "Length Required"),
PRECONDITION_FAILED(412, HttpStatus.Series.CLIENT_ERROR, "Precondition Failed"),
PAYLOAD_TOO_LARGE(413, HttpStatus.Series.CLIENT_ERROR, "Payload Too Large"),
/** @deprecated */
@Deprecated
REQUEST_ENTITY_TOO_LARGE(413, HttpStatus.Series.CLIENT_ERROR, "Request Entity Too Large"),
URI_TOO_LONG(414, HttpStatus.Series.CLIENT_ERROR, "URI Too Long"),
/** @deprecated */
@Deprecated
REQUEST_URI_TOO_LONG(414, HttpStatus.Series.CLIENT_ERROR, "Request-URI Too Long"),
UNSUPPORTED_MEDIA_TYPE(415, HttpStatus.Series.CLIENT_ERROR, "Unsupported Media Type"),
REQUESTED_RANGE_NOT_SATISFIABLE(416, HttpStatus.Series.CLIENT_ERROR, "Requested range not satisfiable"),
EXPECTATION_FAILED(417, HttpStatus.Series.CLIENT_ERROR, "Expectation Failed"),
I_AM_A_TEAPOT(418, HttpStatus.Series.CLIENT_ERROR, "I'm a teapot"),
/** @deprecated */
@Deprecated
INSUFFICIENT_SPACE_ON_RESOURCE(419, HttpStatus.Series.CLIENT_ERROR, "Insufficient Space On Resource"),
/** @deprecated */
@Deprecated
METHOD_FAILURE(420, HttpStatus.Series.CLIENT_ERROR, "Method Failure"),
/** @deprecated */
@Deprecated
DESTINATION_LOCKED(421, HttpStatus.Series.CLIENT_ERROR, "Destination Locked"),
UNPROCESSABLE_ENTITY(422, HttpStatus.Series.CLIENT_ERROR, "Unprocessable Entity"),
LOCKED(423, HttpStatus.Series.CLIENT_ERROR, "Locked"),
FAILED_DEPENDENCY(424, HttpStatus.Series.CLIENT_ERROR, "Failed Dependency"),
TOO_EARLY(425, HttpStatus.Series.CLIENT_ERROR, "Too Early"),
UPGRADE_REQUIRED(426, HttpStatus.Series.CLIENT_ERROR, "Upgrade Required"),
PRECONDITION_REQUIRED(428, HttpStatus.Series.CLIENT_ERROR, "Precondition Required"),
TOO_MANY_REQUESTS(429, HttpStatus.Series.CLIENT_ERROR, "Too Many Requests"),
REQUEST_HEADER_FIELDS_TOO_LARGE(431, HttpStatus.Series.CLIENT_ERROR, "Request Header Fields Too Large"),
UNAVAILABLE_FOR_LEGAL_REASONS(451, HttpStatus.Series.CLIENT_ERROR, "Unavailable For Legal Reasons"),
INTERNAL_SERVER_ERROR(500, HttpStatus.Series.SERVER_ERROR, "Internal Server Error"),
NOT_IMPLEMENTED(501, HttpStatus.Series.SERVER_ERROR, "Not Implemented"),
BAD_GATEWAY(502, HttpStatus.Series.SERVER_ERROR, "Bad Gateway"),
SERVICE_UNAVAILABLE(503, HttpStatus.Series.SERVER_ERROR, "Service Unavailable"),
GATEWAY_TIMEOUT(504, HttpStatus.Series.SERVER_ERROR, "Gateway Timeout"),
HTTP_VERSION_NOT_SUPPORTED(505, HttpStatus.Series.SERVER_ERROR, "HTTP Version not supported"),
VARIANT_ALSO_NEGOTIATES(506, HttpStatus.Series.SERVER_ERROR, "Variant Also Negotiates"),
INSUFFICIENT_STORAGE(507, HttpStatus.Series.SERVER_ERROR, "Insufficient Storage"),
LOOP_DETECTED(508, HttpStatus.Series.SERVER_ERROR, "Loop Detected"),
BANDWIDTH_LIMIT_EXCEEDED(509, HttpStatus.Series.SERVER_ERROR, "Bandwidth Limit Exceeded"),
NOT_EXTENDED(510, HttpStatus.Series.SERVER_ERROR, "Not Extended"),
NETWORK_AUTHENTICATION_REQUIRED(511, HttpStatus.Series.SERVER_ERROR, "Network Authentication Required");
private static final HttpStatus[] VALUES = values();
private final int value;
private final Series series;
private final String reasonPhrase;
private HttpStatus(int value, Series series, String reasonPhrase) {
this.value = value;
this.series = series;
this.reasonPhrase = reasonPhrase;
}
public int value() {
return this.value;
}
public Series series() {
return this.series;
}
public String getReasonPhrase() {
return this.reasonPhrase;
}
public boolean is1xxInformational() {
return this.series() == HttpStatus.Series.INFORMATIONAL;
}
public boolean is2xxSuccessful() {
return this.series() == HttpStatus.Series.SUCCESSFUL;
}
public boolean is3xxRedirection() {
return this.series() == HttpStatus.Series.REDIRECTION;
}
public boolean is4xxClientError() {
return this.series() == HttpStatus.Series.CLIENT_ERROR;
}
public boolean is5xxServerError() {
return this.series() == HttpStatus.Series.SERVER_ERROR;
}
public boolean isError() {
return this.is4xxClientError() || this.is5xxServerError();
}
public String toString() {
int var10000 = this.value;
return "" + var10000 + " " + this.name();
}
public static HttpStatus valueOf(int statusCode) {
HttpStatus status = resolve(statusCode);
if (status == null) {
throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
} else {
return status;
}
}
@Nullable
public static HttpStatus resolve(int statusCode) {
HttpStatus[] var1 = VALUES;
int var2 = var1.length;
for(int var3 = 0; var3 < var2; ++var3) {
HttpStatus status = var1[var3];
if (status.value == statusCode) {
return status;
}
}
return null;
}
public static enum Series {
INFORMATIONAL(1),
SUCCESSFUL(2),
REDIRECTION(3),
CLIENT_ERROR(4),
SERVER_ERROR(5);
private final int value;
private Series(int value) {
this.value = value;
}
public int value() {
return this.value;
}
/** @deprecated */
@Deprecated
public static Series valueOf(HttpStatus status) {
return status.series;
}
public static Series valueOf(int statusCode) {
Series series = resolve(statusCode);
if (series == null) {
throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
} else {
return series;
}
}
@Nullable
public static Series resolve(int statusCode) {
int seriesCode = statusCode / 100;
Series[] var2 = values();
int var3 = var2.length;
for(int var4 = 0; var4 < var3; ++var4) {
Series series = var2[var4];
if (series.value == seriesCode) {
return series;
}
}
return null;
}
}
}
上面代码中的HttpStatus
枚举类定义了HTTP协议中所有标准状态码,以及它们对应的分类(Series
)和描述性短语(reasonPhrase
)。这些状态码被用来表示HTTP响应的状态,并被分为五大类:1xx、2xx、3xx、4xx、5xx。以下是对所有状态码的总结与分类说明:
1. 1xx 信息性响应(Informational Responses)
- 100 CONTINUE: 继续进行请求的一部分,通常是在接收到请求头后。
- 101 SWITCHING PROTOCOLS: 服务器同意切换协议。
- 102 PROCESSING: 服务器已接收请求并正在处理。
- 103 EARLY HINTS: 提供早期的响应提示。
2. 2xx 成功(Successful Responses)
- 200 OK: 请求成功。
- 201 CREATED: 请求已成功并且资源已被创建。
- 202 ACCEPTED: 请求已接受,但尚未处理完成。
- 203 NON-AUTHORITATIVE INFORMATION: 请求成功,但返回的信息不是来自原始服务器。
- 204 NO CONTENT: 请求成功,但不返回任何内容。
- 205 RESET CONTENT: 请求成功,要求客户端重置视图。
- 206 PARTIAL CONTENT: 成功处理了部分 GET 请求。
- 207 MULTI-STATUS: 多状态响应。
- 208 ALREADY REPORTED: DAV 绑定成员已经被列出。
- 226 IM USED: 服务器已经完成请求,并反映了某些内容的变更。
3. 3xx 重定向(Redirection Responses)
- 300 MULTIPLE CHOICES: 有多种选择可供选择。
- 301 MOVED PERMANENTLY: 请求的资源已经永久移动到新位置。
- 302 FOUND: 请求的资源临时移动到新位置。
- 303 SEE OTHER: 客户端应当使用另一个 URI 获取资源。
- 304 NOT MODIFIED: 资源未修改,可继续使用缓存的版本。
- 305 USE PROXY (已废弃): 请求的资源必须通过代理访问。
- 307 TEMPORARY REDIRECT: 请求的资源临时移动到新位置,但方法没有改变。
- 308 PERMANENT REDIRECT: 请求的资源永久移动到新位置,且方法不会改变。
4. 4xx 客户端错误(Client Error Responses)
- 400 BAD REQUEST: 请求无效,通常是因为请求语法错误。
- 401 UNAUTHORIZED: 请求需要用户验证。
- 402 PAYMENT REQUIRED: 保留状态码,通常不使用。
- 403 FORBIDDEN: 服务器拒绝请求,通常是因为权限不足。
- 404 NOT FOUND: 请求的资源无法找到。
- 405 METHOD NOT ALLOWED: 请求的方法不被允许。
- 406 NOT ACCEPTABLE: 服务器无法生成客户端可接受的内容。
- 407 PROXY AUTHENTICATION REQUIRED: 需要代理身份验证。
- 408 REQUEST TIMEOUT: 请求超时,客户端没有在服务器规定的时间内发送请求。
- 409 CONFLICT: 请求的资源存在冲突。
- 410 GONE: 请求的资源已经永久删除。
- 411 LENGTH REQUIRED: 服务器要求请求标明内容长度。
- 412 PRECONDITION FAILED: 服务器未满足请求中的前提条件。
- 413 PAYLOAD TOO LARGE: 请求体过大。
- 414 URI TOO LONG: 请求的 URI 过长。
- 415 UNSUPPORTED MEDIA TYPE: 请求的媒体格式不支持。
- 416 REQUESTED RANGE NOT SATISFIABLE: 请求的范围无效。
- 417 EXPECTATION FAILED: 服务器无法满足请求的预期。
- 418 I AM A TEAPOT: 玩笑性的状态码,意为服务器是个茶壶,无法煮咖啡。
- 422 UNPROCESSABLE ENTITY: 请求格式正确,但语义错误。
- 423 LOCKED: 资源被锁定。
- 424 FAILED DEPENDENCY: 依赖的请求失败。
- 425 TOO EARLY: 服务器拒绝处理,因为请求可能重播。
- 426 UPGRADE REQUIRED: 需要客户端升级协议。
- 428 PRECONDITION REQUIRED: 要求请求预处理条件。
- 429 TOO MANY REQUESTS: 客户端发送了过多的请求。
- 431 REQUEST HEADER FIELDS TOO LARGE: 请求头字段过大。
- 451 UNAVAILABLE FOR LEGAL REASONS: 因法律原因不可用。
5. 5xx 服务器错误(Server Error Responses)
- 500 INTERNAL SERVER ERROR: 服务器内部错误。
- 501 NOT IMPLEMENTED: 服务器不支持请求的方法。
- 502 BAD GATEWAY: 网关或代理服务器收到无效响应。
- 503 SERVICE UNAVAILABLE: 服务器当前无法处理请求。
- 504 GATEWAY TIMEOUT: 网关或代理服务器未能及时从上游服务器获得响应。
- 505 HTTP VERSION NOT SUPPORTED: 服务器不支持请求的 HTTP 版本。
- 506 VARIANT ALSO NEGOTIATES: 服务器有内部配置错误。
- 507 INSUFFICIENT STORAGE: 服务器无法存储请求所需的内容。
- 508 LOOP DETECTED: 服务器检测到无限循环。
- 509 BANDWIDTH LIMIT EXCEEDED: 服务器带宽超出限制。
- 510 NOT EXTENDED: 服务器需要进一步扩展。
- 511 NETWORK AUTHENTICATION REQUIRED: 需要进行网络身份验证。
总结
- 1xx 系列表示信息性状态码,用于指示客户端继续请求。
- 2xx 系列表示成功状态码,表明请求已被成功接收、理解并接受。
- 3xx 系列表示重定向状态码,要求客户端执行进一步的操作以完成请求。
- 4xx 系列表示客户端错误,表明请求包含错误或无法完成。
- 5xx 系列表示服务器错误,表明服务器在尝试处理请求时出错。
这些状态码帮助客户端了解请求的处理状态,并且能够采取相应的动作。
标签:Java,请求,Series,HttpStatus,CLIENT,ERROR,服务器,源码 From: https://blog.csdn.net/qq_42631788/article/details/141331960