Enum Class HttpStatus
- All Implemented Interfaces:
Serializable, Comparable<HttpStatus>, Constable
HTTP Status - HTTP Response Status Code Enumeration
HTTP 状态 - HTTP 响应状态码枚举
This enum defines standard HTTP status codes as specified in RFC 7231.
此枚举定义了 RFC 7231 中规定的标准 HTTP 状态码。
Example | 示例:
HttpStatus status = HttpStatus.OK;
int code = status.getCode();
String reason = status.getReason();
boolean success = status.isSuccess();
Features | 主要功能:
- Standard HTTP status code enumeration - 标准HTTP状态码枚举
- Status category methods (1xx-5xx) - 状态类别方法
- Lookup by status code - 按状态码查找
Usage Examples | 使用示例:
HttpStatus status = HttpStatus.OK;
boolean success = status.isSuccess(); // true
boolean error = status.isError(); // false
HttpStatus found = HttpStatus.fromCode(404);
Security | 安全性:
- Thread-safe: Yes (enum is immutable) - 是(枚举是不可变的)
- Null-safe: No (valueOf throws for unknown codes) - 否(valueOf对未知代码抛出异常)
- Since:
- JDK 25, opencode-base-web V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescription -
Method Summary
Modifier and TypeMethodDescriptionstatic HttpStatusfromCode(int code) Gets HttpStatus from status code.intgetCode()Gets the status code.Gets the reason phrase.booleanChecks if this is a client error response (4xx).booleanisError()Checks if this is an error response (4xx or 5xx).booleanChecks if this is an informational response (1xx).booleanChecks if this is a redirection response (3xx).booleanChecks if this is a server error response (5xx).booleanChecks if this is a successful response (2xx).toString()static HttpStatusvalueOf(int code) Gets HttpStatus from status code, throwing exception if not found.static HttpStatusReturns the enum constant of this class with the specified name.static HttpStatus[]values()Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
CONTINUE
-
SWITCHING_PROTOCOLS
-
PROCESSING
-
EARLY_HINTS
-
OK
-
CREATED
-
ACCEPTED
-
NON_AUTHORITATIVE_INFORMATION
-
NO_CONTENT
-
RESET_CONTENT
-
PARTIAL_CONTENT
-
MULTI_STATUS
-
ALREADY_REPORTED
-
IM_USED
-
MULTIPLE_CHOICES
-
MOVED_PERMANENTLY
-
FOUND
-
SEE_OTHER
-
NOT_MODIFIED
-
USE_PROXY
-
TEMPORARY_REDIRECT
-
PERMANENT_REDIRECT
-
BAD_REQUEST
-
UNAUTHORIZED
-
PAYMENT_REQUIRED
-
FORBIDDEN
-
NOT_FOUND
-
METHOD_NOT_ALLOWED
-
NOT_ACCEPTABLE
-
PROXY_AUTHENTICATION_REQUIRED
-
REQUEST_TIMEOUT
-
CONFLICT
-
GONE
-
LENGTH_REQUIRED
-
PRECONDITION_FAILED
-
PAYLOAD_TOO_LARGE
-
URI_TOO_LONG
-
UNSUPPORTED_MEDIA_TYPE
-
RANGE_NOT_SATISFIABLE
-
EXPECTATION_FAILED
-
IM_A_TEAPOT
-
MISDIRECTED_REQUEST
-
UNPROCESSABLE_ENTITY
-
LOCKED
-
FAILED_DEPENDENCY
-
TOO_EARLY
-
UPGRADE_REQUIRED
-
PRECONDITION_REQUIRED
-
TOO_MANY_REQUESTS
-
REQUEST_HEADER_FIELDS_TOO_LARGE
-
UNAVAILABLE_FOR_LEGAL_REASONS
-
INTERNAL_SERVER_ERROR
-
NOT_IMPLEMENTED
-
BAD_GATEWAY
-
SERVICE_UNAVAILABLE
-
GATEWAY_TIMEOUT
-
HTTP_VERSION_NOT_SUPPORTED
-
VARIANT_ALSO_NEGOTIATES
-
INSUFFICIENT_STORAGE
-
LOOP_DETECTED
-
NOT_EXTENDED
-
NETWORK_AUTHENTICATION_REQUIRED
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-
getCode
public int getCode()Gets the status code. 获取状态码。- Returns:
- the code - 状态码
-
getReason
-
isInformational
public boolean isInformational()Checks if this is an informational response (1xx). 检查是否是信息响应(1xx)。- Returns:
- true if informational - 如果是信息响应返回 true
-
isSuccess
public boolean isSuccess()Checks if this is a successful response (2xx). 检查是否是成功响应(2xx)。- Returns:
- true if success - 如果成功返回 true
-
isRedirection
public boolean isRedirection()Checks if this is a redirection response (3xx). 检查是否是重定向响应(3xx)。- Returns:
- true if redirection - 如果是重定向返回 true
-
isClientError
public boolean isClientError()Checks if this is a client error response (4xx). 检查是否是客户端错误响应(4xx)。- Returns:
- true if client error - 如果是客户端错误返回 true
-
isServerError
public boolean isServerError()Checks if this is a server error response (5xx). 检查是否是服务器错误响应(5xx)。- Returns:
- true if server error - 如果是服务器错误返回 true
-
isError
public boolean isError()Checks if this is an error response (4xx or 5xx). 检查是否是错误响应(4xx 或 5xx)。- Returns:
- true if error - 如果是错误返回 true
-
fromCode
Gets HttpStatus from status code. 从状态码获取 HttpStatus。- Parameters:
code- the status code - 状态码- Returns:
- the HttpStatus or null if not found - HttpStatus 或如果未找到返回 null
-
valueOf
Gets HttpStatus from status code, throwing exception if not found. 从状态码获取 HttpStatus,如果未找到则抛出异常。- Parameters:
code- the status code - 状态码- Returns:
- the HttpStatus - HttpStatus
- Throws:
IllegalArgumentException- if code is not valid - 如果状态码无效
-
toString
- Overrides:
toStringin classEnum<HttpStatus>
-