mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Align HttpStatus with RFC9110
This commit updates the `HttpStatus` enum with the latest changes in RFC9110: * deprecate "413 Payload Too Large" in favor of "413 Content Too Large" * deprecate "418 I'm a teapot" as it was meant as a joke and is now marked as unused * Introduce new "421 Misdirected Request" * deprecate "422 Unprocessable Entity" in favor of "422 Unprocessable Content" * deprecate "509 Bandwidth Limit Exceeded" as it's now unassigned * deprecate "510 Not Extended" as it's now marked as "historic" The relevant exceptions, test matchers and more have been updated as a result. Closes gh-32870
This commit is contained in:
+38
-2
@@ -141,7 +141,9 @@ public class StatusResultMatchers {
|
||||
|
||||
/**
|
||||
* Assert the response status code is {@code HttpStatus.PROCESSING} (102).
|
||||
* @deprecated since 7.0, removed from <a href="https://datatracker.ietf.org/doc/html/rfc4918#section-21.4">WebDAV specification</a>
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
public ResultMatcher isProcessing() {
|
||||
return matcher(HttpStatus.PROCESSING);
|
||||
}
|
||||
@@ -364,10 +366,20 @@ public class StatusResultMatchers {
|
||||
return matcher(HttpStatus.PRECONDITION_FAILED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the response status code is {@code HttpStatus.CONTENT_TOO_LARGE} (413).
|
||||
* @since 7.0
|
||||
*/
|
||||
public ResultMatcher isContentTooLarge() {
|
||||
return matcher(HttpStatus.CONTENT_TOO_LARGE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the response status code is {@code HttpStatus.PAYLOAD_TOO_LARGE} (413).
|
||||
* @since 4.1
|
||||
* @deprecated since 7.0 in favor of {@link #isContentTooLarge()}
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
public ResultMatcher isPayloadTooLarge() {
|
||||
return matcher(HttpStatus.PAYLOAD_TOO_LARGE);
|
||||
}
|
||||
@@ -403,14 +415,34 @@ public class StatusResultMatchers {
|
||||
|
||||
/**
|
||||
* Assert the response status code is {@code HttpStatus.I_AM_A_TEAPOT} (418).
|
||||
* @deprecated since 7.0, this was marked as unused in RFC 9110
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
public ResultMatcher isIAmATeapot() {
|
||||
return matcher(HttpStatus.valueOf(418));
|
||||
return matcher(HttpStatus.I_AM_A_TEAPOT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the response status code is {@code HttpStatus.MISDIRECTED_REQUEST} (421).
|
||||
* @since 7.0
|
||||
*/
|
||||
public ResultMatcher isMisdirectedRequest() {
|
||||
return matcher(HttpStatus.MISDIRECTED_REQUEST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the response status code is {@code HttpStatus.UNPROCESSABLE_CONTENT} (422).
|
||||
* @since 7.0
|
||||
*/
|
||||
public ResultMatcher isUnprocessableContent() {
|
||||
return matcher(HttpStatus.UNPROCESSABLE_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the response status code is {@code HttpStatus.UNPROCESSABLE_ENTITY} (422).
|
||||
* @deprecated since 7.0 in favor of {@link #isUnprocessableContent()}
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
public ResultMatcher isUnprocessableEntity() {
|
||||
return matcher(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
@@ -538,14 +570,18 @@ public class StatusResultMatchers {
|
||||
|
||||
/**
|
||||
* Assert the response status code is {@code HttpStatus.BANDWIDTH_LIMIT_EXCEEDED} (509).
|
||||
* @deprecated since 7.0, since this is now unassigned
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
public ResultMatcher isBandwidthLimitExceeded() {
|
||||
return matcher(HttpStatus.valueOf(509));
|
||||
return matcher(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assert the response status code is {@code HttpStatus.NOT_EXTENDED} (510).
|
||||
* @deprecated since 7.0, this is now marked as "historic" and not endorsed by a standards body.
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
public ResultMatcher isNotExtended() {
|
||||
return matcher(HttpStatus.NOT_EXTENDED);
|
||||
}
|
||||
|
||||
+35
@@ -110,6 +110,8 @@ class StatusResultMatchersDsl internal constructor (private val actions: ResultA
|
||||
/**
|
||||
* @see StatusResultMatchers.isProcessing
|
||||
*/
|
||||
@Deprecated("Removed from WebDAV specification RFC 4918")
|
||||
@Suppress("DEPRECATION")
|
||||
fun isProcessing() {
|
||||
actions.andExpect(matchers.isProcessing())
|
||||
}
|
||||
@@ -325,9 +327,18 @@ class StatusResultMatchersDsl internal constructor (private val actions: ResultA
|
||||
actions.andExpect(matchers.isPreconditionFailed())
|
||||
}
|
||||
|
||||
/**
|
||||
* @see StatusResultMatchers.isContentTooLarge
|
||||
*/
|
||||
fun isContentTooLarge() {
|
||||
actions.andExpect(matchers.isContentTooLarge())
|
||||
}
|
||||
|
||||
/**
|
||||
* @see StatusResultMatchers.isPayloadTooLarge
|
||||
*/
|
||||
@Deprecated("Use Content Too Large instead", replaceWith = ReplaceWith("isContentTooLarge()"))
|
||||
@Suppress("DEPRECATION")
|
||||
fun isPayloadTooLarge() {
|
||||
actions.andExpect(matchers.isPayloadTooLarge())
|
||||
}
|
||||
@@ -363,13 +374,33 @@ class StatusResultMatchersDsl internal constructor (private val actions: ResultA
|
||||
/**
|
||||
* @see StatusResultMatchers.isIAmATeapot
|
||||
*/
|
||||
@Deprecated("Marked as unused in RFC 9110")
|
||||
@Suppress("DEPRECATION")
|
||||
fun isIAmATeapot() {
|
||||
actions.andExpect(matchers.isIAmATeapot())
|
||||
}
|
||||
|
||||
/**
|
||||
* @see StatusResultMatchers.isMisdirectedRequest
|
||||
* @since 7.0
|
||||
*/
|
||||
fun isMisdirectedRequest() {
|
||||
actions.andExpect(matchers.isMisdirectedRequest())
|
||||
}
|
||||
|
||||
/**
|
||||
* @see StatusResultMatchers.isUnprocessableContent
|
||||
* @since 7.0
|
||||
*/
|
||||
fun isUnprocessableContent() {
|
||||
actions.andExpect(matchers.isUnprocessableContent())
|
||||
}
|
||||
|
||||
/**
|
||||
* @see StatusResultMatchers.isUnprocessableEntity
|
||||
*/
|
||||
@Deprecated("Use UnprocessableContent instead.", ReplaceWith("isUnprocessableContent()"))
|
||||
@Suppress("DEPRECATION")
|
||||
fun isUnprocessableEntity() {
|
||||
actions.andExpect(matchers.isUnprocessableEntity())
|
||||
}
|
||||
@@ -496,6 +527,8 @@ class StatusResultMatchersDsl internal constructor (private val actions: ResultA
|
||||
/**
|
||||
* @see StatusResultMatchers.isBandwidthLimitExceeded
|
||||
*/
|
||||
@Deprecated("This is now unassigned")
|
||||
@Suppress("DEPRECATION")
|
||||
fun isBandwidthLimitExceeded() {
|
||||
actions.andExpect(matchers.isBandwidthLimitExceeded())
|
||||
}
|
||||
@@ -503,6 +536,8 @@ class StatusResultMatchersDsl internal constructor (private val actions: ResultA
|
||||
/**
|
||||
* @see StatusResultMatchers.isNotExtended
|
||||
*/
|
||||
@Deprecated("This is marked as 'historic' and is not endorsed by a standards body")
|
||||
@Suppress("DEPRECATION")
|
||||
fun isNotExtended() {
|
||||
actions.andExpect(matchers.isNotExtended())
|
||||
}
|
||||
|
||||
@@ -37,18 +37,20 @@ public enum HttpStatus implements HttpStatusCode {
|
||||
|
||||
/**
|
||||
* {@code 100 Continue}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.2.1">HTTP/1.1: Semantics and Content, section 6.2.1</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-100-continue">HTTP Semantics, section 15.2.1</a>
|
||||
*/
|
||||
CONTINUE(100, Series.INFORMATIONAL, "Continue"),
|
||||
/**
|
||||
* {@code 101 Switching Protocols}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.2.2">HTTP/1.1: Semantics and Content, section 6.2.2</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-101-switching-protocols">HTTP Semantics, section 15.2.2</a>
|
||||
*/
|
||||
SWITCHING_PROTOCOLS(101, Series.INFORMATIONAL, "Switching Protocols"),
|
||||
/**
|
||||
* {@code 102 Processing}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc2518#section-10.1">WebDAV</a>
|
||||
* @deprecated since 7.0, removed from <a href="https://datatracker.ietf.org/doc/html/rfc4918#section-21.4">WebDAV specification</a>
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
PROCESSING(102, Series.INFORMATIONAL, "Processing"),
|
||||
/**
|
||||
* {@code 103 Early Hints}.
|
||||
@@ -61,42 +63,42 @@ public enum HttpStatus implements HttpStatusCode {
|
||||
|
||||
/**
|
||||
* {@code 200 OK}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.1">HTTP/1.1: Semantics and Content, section 6.3.1</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-200-ok">HTTP Semantics, section 15.3.1</a>
|
||||
*/
|
||||
OK(200, Series.SUCCESSFUL, "OK"),
|
||||
/**
|
||||
* {@code 201 Created}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.2">HTTP/1.1: Semantics and Content, section 6.3.2</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-201-created">HTTP Semantics, section 15.3.2</a>
|
||||
*/
|
||||
CREATED(201, Series.SUCCESSFUL, "Created"),
|
||||
/**
|
||||
* {@code 202 Accepted}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.3">HTTP/1.1: Semantics and Content, section 6.3.3</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-202-accepted">HTTP Semantics, section 15.3.3</a>
|
||||
*/
|
||||
ACCEPTED(202, Series.SUCCESSFUL, "Accepted"),
|
||||
/**
|
||||
* {@code 203 Non-Authoritative Information}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.4">HTTP/1.1: Semantics and Content, section 6.3.4</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-203-non-authoritative-infor">HTTP Semantics, section 15.3.4</a>
|
||||
*/
|
||||
NON_AUTHORITATIVE_INFORMATION(203, Series.SUCCESSFUL, "Non-Authoritative Information"),
|
||||
/**
|
||||
* {@code 204 No Content}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.5">HTTP/1.1: Semantics and Content, section 6.3.5</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-204-no-content">HTTP Semantics, section 15.3.5</a>
|
||||
*/
|
||||
NO_CONTENT(204, Series.SUCCESSFUL, "No Content"),
|
||||
/**
|
||||
* {@code 205 Reset Content}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.3.6">HTTP/1.1: Semantics and Content, section 6.3.6</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-205-reset-content">HTTP Semantics, section 15.3.6</a>
|
||||
*/
|
||||
RESET_CONTENT(205, Series.SUCCESSFUL, "Reset Content"),
|
||||
/**
|
||||
* {@code 206 Partial Content}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7233#section-4.1">HTTP/1.1: Range Requests, section 4.1</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-206-partial-content">HTTP/1.1: Range Requests, section 4.1</a>
|
||||
*/
|
||||
PARTIAL_CONTENT(206, Series.SUCCESSFUL, "Partial Content"),
|
||||
/**
|
||||
* {@code 207 Multi-Status}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4918#section-13">WebDAV</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc4918#section-11.1">WebDAV</a>
|
||||
*/
|
||||
MULTI_STATUS(207, Series.SUCCESSFUL, "Multi-Status"),
|
||||
/**
|
||||
@@ -114,37 +116,37 @@ public enum HttpStatus implements HttpStatusCode {
|
||||
|
||||
/**
|
||||
* {@code 300 Multiple Choices}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.1">HTTP/1.1: Semantics and Content, section 6.4.1</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-300-multiple-choices">HTTP Semantics, section 15.4.1</a>
|
||||
*/
|
||||
MULTIPLE_CHOICES(300, Series.REDIRECTION, "Multiple Choices"),
|
||||
/**
|
||||
* {@code 301 Moved Permanently}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.2">HTTP/1.1: Semantics and Content, section 6.4.2</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-301-moved-permanently">HTTP Semantics, section 15.4.2</a>
|
||||
*/
|
||||
MOVED_PERMANENTLY(301, Series.REDIRECTION, "Moved Permanently"),
|
||||
/**
|
||||
* {@code 302 Found}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.3">HTTP/1.1: Semantics and Content, section 6.4.3</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-302-found">HTTP Semantics, section 15.4.3</a>
|
||||
*/
|
||||
FOUND(302, Series.REDIRECTION, "Found"),
|
||||
/**
|
||||
* {@code 303 See Other}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.4">HTTP/1.1: Semantics and Content, section 6.4.4</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-303-see-other">HTTP Semantics, section 15.4.4</a>
|
||||
*/
|
||||
SEE_OTHER(303, Series.REDIRECTION, "See Other"),
|
||||
/**
|
||||
* {@code 304 Not Modified}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7232#section-4.1">HTTP/1.1: Conditional Requests, section 4.1</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-304-not-modified">HTTP Semantics, section 15.4.5</a>
|
||||
*/
|
||||
NOT_MODIFIED(304, Series.REDIRECTION, "Not Modified"),
|
||||
/**
|
||||
* {@code 307 Temporary Redirect}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.4.7">HTTP/1.1: Semantics and Content, section 6.4.7</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-307-temporary-redirect">HTTP Semantics, section 15.4.8</a>
|
||||
*/
|
||||
TEMPORARY_REDIRECT(307, Series.REDIRECTION, "Temporary Redirect"),
|
||||
/**
|
||||
* {@code 308 Permanent Redirect}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7238">RFC 7238</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-308-permanent-redirect">HTTP Semantics, section 15.4.9</a>
|
||||
*/
|
||||
PERMANENT_REDIRECT(308, Series.REDIRECTION, "Permanent Redirect"),
|
||||
|
||||
@@ -152,70 +154,70 @@ public enum HttpStatus implements HttpStatusCode {
|
||||
|
||||
/**
|
||||
* {@code 400 Bad Request}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.1">HTTP/1.1: Semantics and Content, section 6.5.1</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-400-bad-request">HTTP Semantics, section 15.5.1</a>
|
||||
*/
|
||||
BAD_REQUEST(400, Series.CLIENT_ERROR, "Bad Request"),
|
||||
/**
|
||||
* {@code 401 Unauthorized}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7235#section-3.1">HTTP/1.1: Authentication, section 3.1</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-401-unauthorized">HTTP Semantics, section 15.5.2</a>
|
||||
*/
|
||||
UNAUTHORIZED(401, Series.CLIENT_ERROR, "Unauthorized"),
|
||||
/**
|
||||
* {@code 402 Payment Required}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.2">HTTP/1.1: Semantics and Content, section 6.5.2</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-402-payment-required">HTTP Semantics, section 15.5.3</a>
|
||||
*/
|
||||
PAYMENT_REQUIRED(402, Series.CLIENT_ERROR, "Payment Required"),
|
||||
/**
|
||||
* {@code 403 Forbidden}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.3">HTTP/1.1: Semantics and Content, section 6.5.3</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-403-forbidden">HTTP Semantics, section 15.5.4</a>
|
||||
*/
|
||||
FORBIDDEN(403, Series.CLIENT_ERROR, "Forbidden"),
|
||||
/**
|
||||
* {@code 404 Not Found}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.4">HTTP/1.1: Semantics and Content, section 6.5.4</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-404-not-found">HTTP Semantics, section 15.5.5</a>
|
||||
*/
|
||||
NOT_FOUND(404, Series.CLIENT_ERROR, "Not Found"),
|
||||
/**
|
||||
* {@code 405 Method Not Allowed}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.5">HTTP/1.1: Semantics and Content, section 6.5.5</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-405-method-not-allowed">HTTP Semantics, section 15.5.6</a>
|
||||
*/
|
||||
METHOD_NOT_ALLOWED(405, Series.CLIENT_ERROR, "Method Not Allowed"),
|
||||
/**
|
||||
* {@code 406 Not Acceptable}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.6">HTTP/1.1: Semantics and Content, section 6.5.6</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-406-not-acceptable">HTTP Semantics, section 15.5.7</a>
|
||||
*/
|
||||
NOT_ACCEPTABLE(406, Series.CLIENT_ERROR, "Not Acceptable"),
|
||||
/**
|
||||
* {@code 407 Proxy Authentication Required}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7235#section-3.2">HTTP/1.1: Authentication, section 3.2</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-407-proxy-authentication-re">HTTP Semantics, section 15.5.8</a>
|
||||
*/
|
||||
PROXY_AUTHENTICATION_REQUIRED(407, Series.CLIENT_ERROR, "Proxy Authentication Required"),
|
||||
/**
|
||||
* {@code 408 Request Timeout}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.7">HTTP/1.1: Semantics and Content, section 6.5.7</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-408-request-timeout">HTTP Semantics, section 15.5.9</a>
|
||||
*/
|
||||
REQUEST_TIMEOUT(408, Series.CLIENT_ERROR, "Request Timeout"),
|
||||
/**
|
||||
* {@code 409 Conflict}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.8">HTTP/1.1: Semantics and Content, section 6.5.8</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-409-conflict">HTTP Semantics, section 15.5.10</a>
|
||||
*/
|
||||
CONFLICT(409, Series.CLIENT_ERROR, "Conflict"),
|
||||
/**
|
||||
* {@code 410 Gone}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.9">
|
||||
* HTTP/1.1: Semantics and Content, section 6.5.9</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-410-gone">
|
||||
* HTTP Semantics, section 15.5.11</a>
|
||||
*/
|
||||
GONE(410, Series.CLIENT_ERROR, "Gone"),
|
||||
/**
|
||||
* {@code 411 Length Required}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.10">
|
||||
* HTTP/1.1: Semantics and Content, section 6.5.10</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-411-length-required">
|
||||
* HTTP Semantics, section 15.5.12</a>
|
||||
*/
|
||||
LENGTH_REQUIRED(411, Series.CLIENT_ERROR, "Length Required"),
|
||||
/**
|
||||
* {@code 412 Precondition failed}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7232#section-4.2">
|
||||
* HTTP/1.1: Conditional Requests, section 4.2</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-412-precondition-failed">
|
||||
* HTTP Semantics, section 15.5.13</a>
|
||||
*/
|
||||
PRECONDITION_FAILED(412, Series.CLIENT_ERROR, "Precondition Failed"),
|
||||
/**
|
||||
@@ -223,41 +225,67 @@ public enum HttpStatus implements HttpStatusCode {
|
||||
* @since 4.1
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.11">
|
||||
* HTTP/1.1: Semantics and Content, section 6.5.11</a>
|
||||
* @deprecated since 7.0 in favor of {@link #CONTENT_TOO_LARGE}
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
PAYLOAD_TOO_LARGE(413, Series.CLIENT_ERROR, "Payload Too Large"),
|
||||
/**
|
||||
* {@code 413 Content Too Large}.
|
||||
* @since 7.0
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-413-content-too-large">
|
||||
* HTTP Semantics, section 15.5.14</a>
|
||||
*/
|
||||
CONTENT_TOO_LARGE(413, Series.CLIENT_ERROR, "Content Too Large"),
|
||||
/**
|
||||
* {@code 414 URI Too Long}.
|
||||
* @since 4.1
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.12">
|
||||
* HTTP/1.1: Semantics and Content, section 6.5.12</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-414-uri-too-long">
|
||||
* HTTP Semantics, section 15.5.15</a>
|
||||
*/
|
||||
URI_TOO_LONG(414, Series.CLIENT_ERROR, "URI Too Long"),
|
||||
/**
|
||||
* {@code 415 Unsupported Media Type}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.13">
|
||||
* HTTP/1.1: Semantics and Content, section 6.5.13</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-415-unsupported-media-type">
|
||||
* HTTP Semantics, section 15.5.16</a>
|
||||
*/
|
||||
UNSUPPORTED_MEDIA_TYPE(415, Series.CLIENT_ERROR, "Unsupported Media Type"),
|
||||
/**
|
||||
* {@code 416 Requested Range Not Satisfiable}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7233#section-4.4">HTTP/1.1: Range Requests, section 4.4</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-416-range-not-satisfiable">
|
||||
* HTTP Semantics, section 15.5.17</a>
|
||||
*/
|
||||
REQUESTED_RANGE_NOT_SATISFIABLE(416, Series.CLIENT_ERROR, "Requested range not satisfiable"),
|
||||
/**
|
||||
* {@code 417 Expectation Failed}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.5.14">
|
||||
* HTTP/1.1: Semantics and Content, section 6.5.14</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-417-expectation-failed">
|
||||
* HTTP Semantics, section 15.5.18</a>
|
||||
*/
|
||||
EXPECTATION_FAILED(417, Series.CLIENT_ERROR, "Expectation Failed"),
|
||||
/**
|
||||
* {@code 418 I'm a teapot}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc2324#section-2.3.2">HTCPCP/1.0</a>
|
||||
* @deprecated since 7.0, marked as unused in RFC 9110
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
I_AM_A_TEAPOT(418, Series.CLIENT_ERROR, "I'm a teapot"),
|
||||
/**
|
||||
* {@code 421 Misdirected Request}.
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-421-misdirected-request">
|
||||
* HTTP Semantics, section 15.5.20</a>
|
||||
*/
|
||||
MISDIRECTED_REQUEST(421, Series.CLIENT_ERROR, "Misdirected Request"),
|
||||
/**
|
||||
* {@code 422 Unprocessable Content}.
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-422-unprocessable-content">
|
||||
* HTTP Semantics, section 15.5.21</a>
|
||||
*/
|
||||
UNPROCESSABLE_CONTENT(422, Series.CLIENT_ERROR, "Unprocessable Content"),
|
||||
/**
|
||||
* {@code 422 Unprocessable Entity}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc4918#section-11.2">WebDAV</a>
|
||||
* @deprecated since 7.0 in favor of {@link #UNPROCESSABLE_CONTENT}
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
UNPROCESSABLE_ENTITY(422, Series.CLIENT_ERROR, "Unprocessable Entity"),
|
||||
/**
|
||||
* {@code 423 Locked}.
|
||||
@@ -277,7 +305,8 @@ public enum HttpStatus implements HttpStatusCode {
|
||||
TOO_EARLY(425, Series.CLIENT_ERROR, "Too Early"),
|
||||
/**
|
||||
* {@code 426 Upgrade Required}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc2817#section-6">Upgrading to TLS Within HTTP/1.1</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-426-upgrade-required">
|
||||
* HTTP Semantics, section 15.5.22</a>
|
||||
*/
|
||||
UPGRADE_REQUIRED(426, Series.CLIENT_ERROR, "Upgrade Required"),
|
||||
/**
|
||||
@@ -307,32 +336,32 @@ public enum HttpStatus implements HttpStatusCode {
|
||||
|
||||
/**
|
||||
* {@code 500 Internal Server Error}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.1">HTTP/1.1: Semantics and Content, section 6.6.1</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#section-15.6.1">HTTP Semantics, section 15.6.1</a>
|
||||
*/
|
||||
INTERNAL_SERVER_ERROR(500, Series.SERVER_ERROR, "Internal Server Error"),
|
||||
/**
|
||||
* {@code 501 Not Implemented}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.2">HTTP/1.1: Semantics and Content, section 6.6.2</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-501-not-implemented">HTTP Semantics, section 15.6.2</a>
|
||||
*/
|
||||
NOT_IMPLEMENTED(501, Series.SERVER_ERROR, "Not Implemented"),
|
||||
/**
|
||||
* {@code 502 Bad Gateway}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.3">HTTP/1.1: Semantics and Content, section 6.6.3</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-502-bad-gateway">HTTP Semantics, section 15.6.3</a>
|
||||
*/
|
||||
BAD_GATEWAY(502, Series.SERVER_ERROR, "Bad Gateway"),
|
||||
/**
|
||||
* {@code 503 Service Unavailable}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.4">HTTP/1.1: Semantics and Content, section 6.6.4</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-503-service-unavailable">HTTP Semantics, section 15.6.4</a>
|
||||
*/
|
||||
SERVICE_UNAVAILABLE(503, Series.SERVER_ERROR, "Service Unavailable"),
|
||||
/**
|
||||
* {@code 504 Gateway Timeout}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.5">HTTP/1.1: Semantics and Content, section 6.6.5</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-504-gateway-timeout">HTTP Semantics, section 15.6.5</a>
|
||||
*/
|
||||
GATEWAY_TIMEOUT(504, Series.SERVER_ERROR, "Gateway Timeout"),
|
||||
/**
|
||||
* {@code 505 HTTP Version Not Supported}.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-6.6.6">HTTP/1.1: Semantics and Content, section 6.6.6</a>
|
||||
* @see <a href="https://datatracker.ietf.org/doc/html/rfc9110#name-505-http-version-not-suppor">HTTP Semantics, section 15.6.6</a>
|
||||
*/
|
||||
HTTP_VERSION_NOT_SUPPORTED(505, Series.SERVER_ERROR, "HTTP Version not supported"),
|
||||
/**
|
||||
@@ -352,12 +381,16 @@ public enum HttpStatus implements HttpStatusCode {
|
||||
LOOP_DETECTED(508, Series.SERVER_ERROR, "Loop Detected"),
|
||||
/**
|
||||
* {@code 509 Bandwidth Limit Exceeded}
|
||||
* @deprecated since 7.0, this is now unassigned
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
BANDWIDTH_LIMIT_EXCEEDED(509, Series.SERVER_ERROR, "Bandwidth Limit Exceeded"),
|
||||
/**
|
||||
* {@code 510 Not Extended}
|
||||
* @see <a href="https://tools.ietf.org/html/rfc2774#section-7">HTTP Extension Framework</a>
|
||||
* @deprecated since 7.0, this is now marked as "historic" and not endorsed by a standards body.
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
NOT_EXTENDED(510, Series.SERVER_ERROR, "Not Extended"),
|
||||
/**
|
||||
* {@code 511 Network Authentication Required}.
|
||||
|
||||
@@ -362,12 +362,24 @@ public class ResponseEntity<T> extends HttpEntity<T> {
|
||||
return status(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder with an
|
||||
* {@linkplain HttpStatus#UNPROCESSABLE_CONTENT UNPROCESSABLE_CONTENT} status.
|
||||
* @return the created builder
|
||||
* @since 7.0
|
||||
*/
|
||||
public static BodyBuilder unprocessableContent() {
|
||||
return status(HttpStatus.UNPROCESSABLE_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder with an
|
||||
* {@linkplain HttpStatus#UNPROCESSABLE_ENTITY UNPROCESSABLE_ENTITY} status.
|
||||
* @return the created builder
|
||||
* @since 4.1.3
|
||||
* @deprecated since 7.0 in favor of {@link #unprocessableContent()}
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
public static BodyBuilder unprocessableEntity() {
|
||||
return status(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
@@ -133,6 +133,9 @@ public class HttpClientErrorException extends HttpStatusCodeException {
|
||||
case UNPROCESSABLE_ENTITY -> message != null ?
|
||||
new UnprocessableEntity(message, statusText, headers, body, charset) :
|
||||
new UnprocessableEntity(statusText, headers, body, charset);
|
||||
case UNPROCESSABLE_CONTENT -> message != null ?
|
||||
new UnprocessableContent(message, statusText, headers, body, charset) :
|
||||
new UnprocessableContent(statusText, headers, body, charset);
|
||||
default -> message != null ?
|
||||
new HttpClientErrorException(message, statusCode, statusText, headers, body, charset) :
|
||||
new HttpClientErrorException(statusCode, statusText, headers, body, charset);
|
||||
@@ -307,10 +310,30 @@ public class HttpClientErrorException extends HttpStatusCodeException {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link HttpClientErrorException} for status HTTP 422 Unprocessable Content.
|
||||
* @since 7.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static final class UnprocessableContent extends HttpClientErrorException {
|
||||
|
||||
private UnprocessableContent(String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
|
||||
super(HttpStatus.UNPROCESSABLE_CONTENT, statusText, headers, body, charset);
|
||||
}
|
||||
|
||||
private UnprocessableContent(String message, String statusText,
|
||||
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
|
||||
|
||||
super(message, HttpStatus.UNPROCESSABLE_CONTENT, statusText, headers, body, charset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link HttpClientErrorException} for status HTTP 422 Unprocessable Entity.
|
||||
* @since 5.1
|
||||
* @deprecated since 7.0 in favor of {@link UnprocessableContent}
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
@SuppressWarnings("serial")
|
||||
public static final class UnprocessableEntity extends HttpClientErrorException {
|
||||
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ import org.springframework.web.ErrorResponse;
|
||||
public class MaxUploadSizeExceededException extends MultipartException implements ErrorResponse {
|
||||
|
||||
private final ProblemDetail body =
|
||||
ProblemDetail.forStatusAndDetail(HttpStatus.PAYLOAD_TOO_LARGE, "Maximum upload size exceeded");
|
||||
ProblemDetail.forStatusAndDetail(HttpStatus.CONTENT_TOO_LARGE, "Maximum upload size exceeded");
|
||||
|
||||
private final long maxUploadSize;
|
||||
|
||||
@@ -71,7 +71,7 @@ public class MaxUploadSizeExceededException extends MultipartException implement
|
||||
|
||||
@Override
|
||||
public HttpStatusCode getStatusCode() {
|
||||
return HttpStatus.PAYLOAD_TOO_LARGE;
|
||||
return HttpStatus.CONTENT_TOO_LARGE;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2002-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.web.server;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
/**
|
||||
* Exception for errors that fit response status 413 (Content too large) for use in
|
||||
* Spring Web applications.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 7.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ContentTooLargeException extends ResponseStatusException {
|
||||
|
||||
public ContentTooLargeException(@Nullable Throwable cause) {
|
||||
super(HttpStatus.CONTENT_TOO_LARGE, null, cause);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -27,8 +27,10 @@ import org.springframework.http.HttpStatus;
|
||||
*
|
||||
* @author Kim Bosung
|
||||
* @since 6.2
|
||||
* @deprecated since 7.0 in favor of {@link ContentTooLargeException}
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Deprecated(since = "7.0")
|
||||
public class PayloadTooLargeException extends ResponseStatusException {
|
||||
|
||||
public PayloadTooLargeException(@Nullable Throwable cause) {
|
||||
|
||||
@@ -16,12 +16,15 @@
|
||||
|
||||
package org.springframework.http;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
@@ -29,86 +32,89 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class HttpStatusTests {
|
||||
|
||||
private final Map<Integer, String> statusCodes = new LinkedHashMap<>();
|
||||
private final MultiValueMap<Integer, String> statusCodes = new LinkedMultiValueMap<>();
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void createStatusCodes() {
|
||||
statusCodes.put(100, "CONTINUE");
|
||||
statusCodes.put(101, "SWITCHING_PROTOCOLS");
|
||||
statusCodes.put(102, "PROCESSING");
|
||||
statusCodes.put(103, "EARLY_HINTS");
|
||||
statusCodes.add(100, "CONTINUE");
|
||||
statusCodes.add(101, "SWITCHING_PROTOCOLS");
|
||||
statusCodes.add(102, "PROCESSING");
|
||||
statusCodes.add(103, "EARLY_HINTS");
|
||||
|
||||
statusCodes.put(200, "OK");
|
||||
statusCodes.put(201, "CREATED");
|
||||
statusCodes.put(202, "ACCEPTED");
|
||||
statusCodes.put(203, "NON_AUTHORITATIVE_INFORMATION");
|
||||
statusCodes.put(204, "NO_CONTENT");
|
||||
statusCodes.put(205, "RESET_CONTENT");
|
||||
statusCodes.put(206, "PARTIAL_CONTENT");
|
||||
statusCodes.put(207, "MULTI_STATUS");
|
||||
statusCodes.put(208, "ALREADY_REPORTED");
|
||||
statusCodes.put(226, "IM_USED");
|
||||
statusCodes.add(200, "OK");
|
||||
statusCodes.add(201, "CREATED");
|
||||
statusCodes.add(202, "ACCEPTED");
|
||||
statusCodes.add(203, "NON_AUTHORITATIVE_INFORMATION");
|
||||
statusCodes.add(204, "NO_CONTENT");
|
||||
statusCodes.add(205, "RESET_CONTENT");
|
||||
statusCodes.add(206, "PARTIAL_CONTENT");
|
||||
statusCodes.add(207, "MULTI_STATUS");
|
||||
statusCodes.add(208, "ALREADY_REPORTED");
|
||||
statusCodes.add(226, "IM_USED");
|
||||
|
||||
statusCodes.put(300, "MULTIPLE_CHOICES");
|
||||
statusCodes.put(301, "MOVED_PERMANENTLY");
|
||||
statusCodes.put(302, "FOUND");
|
||||
statusCodes.put(303, "SEE_OTHER");
|
||||
statusCodes.put(304, "NOT_MODIFIED");
|
||||
statusCodes.put(307, "TEMPORARY_REDIRECT");
|
||||
statusCodes.put(308, "PERMANENT_REDIRECT");
|
||||
statusCodes.add(300, "MULTIPLE_CHOICES");
|
||||
statusCodes.add(301, "MOVED_PERMANENTLY");
|
||||
statusCodes.add(302, "FOUND");
|
||||
statusCodes.add(303, "SEE_OTHER");
|
||||
statusCodes.add(304, "NOT_MODIFIED");
|
||||
statusCodes.add(307, "TEMPORARY_REDIRECT");
|
||||
statusCodes.add(308, "PERMANENT_REDIRECT");
|
||||
|
||||
statusCodes.put(400, "BAD_REQUEST");
|
||||
statusCodes.put(401, "UNAUTHORIZED");
|
||||
statusCodes.put(402, "PAYMENT_REQUIRED");
|
||||
statusCodes.put(403, "FORBIDDEN");
|
||||
statusCodes.put(404, "NOT_FOUND");
|
||||
statusCodes.put(405, "METHOD_NOT_ALLOWED");
|
||||
statusCodes.put(406, "NOT_ACCEPTABLE");
|
||||
statusCodes.put(407, "PROXY_AUTHENTICATION_REQUIRED");
|
||||
statusCodes.put(408, "REQUEST_TIMEOUT");
|
||||
statusCodes.put(409, "CONFLICT");
|
||||
statusCodes.put(410, "GONE");
|
||||
statusCodes.put(411, "LENGTH_REQUIRED");
|
||||
statusCodes.put(412, "PRECONDITION_FAILED");
|
||||
statusCodes.put(413, "PAYLOAD_TOO_LARGE");
|
||||
statusCodes.put(414, "URI_TOO_LONG");
|
||||
statusCodes.put(415, "UNSUPPORTED_MEDIA_TYPE");
|
||||
statusCodes.put(416, "REQUESTED_RANGE_NOT_SATISFIABLE");
|
||||
statusCodes.put(417, "EXPECTATION_FAILED");
|
||||
statusCodes.put(418, "I_AM_A_TEAPOT");
|
||||
statusCodes.put(422, "UNPROCESSABLE_ENTITY");
|
||||
statusCodes.put(423, "LOCKED");
|
||||
statusCodes.put(424, "FAILED_DEPENDENCY");
|
||||
statusCodes.put(425, "TOO_EARLY");
|
||||
statusCodes.put(426, "UPGRADE_REQUIRED");
|
||||
statusCodes.put(428, "PRECONDITION_REQUIRED");
|
||||
statusCodes.put(429, "TOO_MANY_REQUESTS");
|
||||
statusCodes.put(431, "REQUEST_HEADER_FIELDS_TOO_LARGE");
|
||||
statusCodes.put(451, "UNAVAILABLE_FOR_LEGAL_REASONS");
|
||||
statusCodes.add(400, "BAD_REQUEST");
|
||||
statusCodes.add(401, "UNAUTHORIZED");
|
||||
statusCodes.add(402, "PAYMENT_REQUIRED");
|
||||
statusCodes.add(403, "FORBIDDEN");
|
||||
statusCodes.add(404, "NOT_FOUND");
|
||||
statusCodes.add(405, "METHOD_NOT_ALLOWED");
|
||||
statusCodes.add(406, "NOT_ACCEPTABLE");
|
||||
statusCodes.add(407, "PROXY_AUTHENTICATION_REQUIRED");
|
||||
statusCodes.add(408, "REQUEST_TIMEOUT");
|
||||
statusCodes.add(409, "CONFLICT");
|
||||
statusCodes.add(410, "GONE");
|
||||
statusCodes.add(411, "LENGTH_REQUIRED");
|
||||
statusCodes.add(412, "PRECONDITION_FAILED");
|
||||
statusCodes.add(413, "PAYLOAD_TOO_LARGE");
|
||||
statusCodes.add(413, "CONTENT_TOO_LARGE");
|
||||
statusCodes.add(414, "URI_TOO_LONG");
|
||||
statusCodes.add(415, "UNSUPPORTED_MEDIA_TYPE");
|
||||
statusCodes.add(416, "REQUESTED_RANGE_NOT_SATISFIABLE");
|
||||
statusCodes.add(417, "EXPECTATION_FAILED");
|
||||
statusCodes.add(418, "I_AM_A_TEAPOT");
|
||||
statusCodes.add(421, "MISDIRECTED_REQUEST");
|
||||
statusCodes.add(422, "UNPROCESSABLE_CONTENT");
|
||||
statusCodes.add(422, "UNPROCESSABLE_ENTITY");
|
||||
statusCodes.add(423, "LOCKED");
|
||||
statusCodes.add(424, "FAILED_DEPENDENCY");
|
||||
statusCodes.add(425, "TOO_EARLY");
|
||||
statusCodes.add(426, "UPGRADE_REQUIRED");
|
||||
statusCodes.add(428, "PRECONDITION_REQUIRED");
|
||||
statusCodes.add(429, "TOO_MANY_REQUESTS");
|
||||
statusCodes.add(431, "REQUEST_HEADER_FIELDS_TOO_LARGE");
|
||||
statusCodes.add(451, "UNAVAILABLE_FOR_LEGAL_REASONS");
|
||||
|
||||
statusCodes.put(500, "INTERNAL_SERVER_ERROR");
|
||||
statusCodes.put(501, "NOT_IMPLEMENTED");
|
||||
statusCodes.put(502, "BAD_GATEWAY");
|
||||
statusCodes.put(503, "SERVICE_UNAVAILABLE");
|
||||
statusCodes.put(504, "GATEWAY_TIMEOUT");
|
||||
statusCodes.put(505, "HTTP_VERSION_NOT_SUPPORTED");
|
||||
statusCodes.put(506, "VARIANT_ALSO_NEGOTIATES");
|
||||
statusCodes.put(507, "INSUFFICIENT_STORAGE");
|
||||
statusCodes.put(508, "LOOP_DETECTED");
|
||||
statusCodes.put(509, "BANDWIDTH_LIMIT_EXCEEDED");
|
||||
statusCodes.put(510, "NOT_EXTENDED");
|
||||
statusCodes.put(511, "NETWORK_AUTHENTICATION_REQUIRED");
|
||||
statusCodes.add(500, "INTERNAL_SERVER_ERROR");
|
||||
statusCodes.add(501, "NOT_IMPLEMENTED");
|
||||
statusCodes.add(502, "BAD_GATEWAY");
|
||||
statusCodes.add(503, "SERVICE_UNAVAILABLE");
|
||||
statusCodes.add(504, "GATEWAY_TIMEOUT");
|
||||
statusCodes.add(505, "HTTP_VERSION_NOT_SUPPORTED");
|
||||
statusCodes.add(506, "VARIANT_ALSO_NEGOTIATES");
|
||||
statusCodes.add(507, "INSUFFICIENT_STORAGE");
|
||||
statusCodes.add(508, "LOOP_DETECTED");
|
||||
statusCodes.add(509, "BANDWIDTH_LIMIT_EXCEEDED");
|
||||
statusCodes.add(510, "NOT_EXTENDED");
|
||||
statusCodes.add(511, "NETWORK_AUTHENTICATION_REQUIRED");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void fromMapToEnum() {
|
||||
for (Map.Entry<Integer, String> entry : statusCodes.entrySet()) {
|
||||
for (Map.Entry<Integer, List<String>> entry : statusCodes.entrySet()) {
|
||||
int value = entry.getKey();
|
||||
HttpStatus status = HttpStatus.valueOf(value);
|
||||
assertThat(status.value()).as("Invalid value").isEqualTo(value);
|
||||
assertThat(status.name()).as("Invalid name for [" + value + "]").isEqualTo(entry.getValue());
|
||||
assertThat(entry.getValue()).as("Invalid name for [" + value + "]").contains(status.name());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +123,7 @@ class HttpStatusTests {
|
||||
for (HttpStatus status : HttpStatus.values()) {
|
||||
int code = status.value();
|
||||
assertThat(statusCodes).as("Map has no value for [" + code + "]").containsKey(code);
|
||||
assertThat(status.name()).as("Invalid name for [" + code + "]").isEqualTo(statusCodes.get(code));
|
||||
assertThat(statusCodes.get(code)).as("Invalid name for [" + code + "]").contains(status.name());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -166,6 +166,16 @@ class ResponseEntityTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void unprocessableContent() {
|
||||
ResponseEntity<String> responseEntity = ResponseEntity.unprocessableContent().body("error");
|
||||
|
||||
assertThat(responseEntity).isNotNull();
|
||||
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_CONTENT);
|
||||
assertThat(responseEntity.getBody()).isEqualTo("error");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecate")
|
||||
void unprocessableEntity() {
|
||||
ResponseEntity<String> responseEntity = ResponseEntity.unprocessableEntity().body("error");
|
||||
|
||||
|
||||
+20
-2
@@ -465,10 +465,28 @@ public class WebClientResponseException extends WebClientException {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link WebClientResponseException} for status HTTP 422 Unprocessable Entity.
|
||||
* @since 5.1
|
||||
* {@link WebClientResponseException} for status HTTP 422 Unprocessable Content.
|
||||
* @since 7.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public static class UnprocessableContent extends WebClientResponseException {
|
||||
|
||||
UnprocessableContent(
|
||||
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset,
|
||||
@Nullable HttpRequest request) {
|
||||
|
||||
super(HttpStatus.UNPROCESSABLE_CONTENT.value(), statusText, headers, body, charset, request);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link WebClientResponseException} for status HTTP 422 Unprocessable Entity.
|
||||
* @since 5.1
|
||||
* @deprecated since 7.0 in favor of {@link UnprocessableContent}
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Deprecated(since = "7.0")
|
||||
public static class UnprocessableEntity extends WebClientResponseException {
|
||||
|
||||
UnprocessableEntity(
|
||||
|
||||
+12
-1
@@ -214,9 +214,20 @@ public interface ServerResponse {
|
||||
|
||||
/**
|
||||
* Create a builder with an
|
||||
* {@linkplain HttpStatus#UNPROCESSABLE_ENTITY 422 Unprocessable Entity} status.
|
||||
* {@linkplain HttpStatus#UNPROCESSABLE_CONTENT 422 Unprocessable Content} status.
|
||||
* @return the created builder
|
||||
*/
|
||||
static BodyBuilder unprocessableContent() {
|
||||
return status(HttpStatus.UNPROCESSABLE_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder with an
|
||||
* {@linkplain HttpStatus#UNPROCESSABLE_ENTITY 422 Unprocessable Entity} status.
|
||||
* @return the created builder
|
||||
* @deprecated since 7.0 in favor of {@link #unprocessableContent()}
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
static BodyBuilder unprocessableEntity() {
|
||||
return status(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
+2
-2
@@ -52,7 +52,7 @@ import org.springframework.web.bind.support.WebExchangeBindException;
|
||||
import org.springframework.web.bind.support.WebExchangeDataBinder;
|
||||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport;
|
||||
import org.springframework.web.server.PayloadTooLargeException;
|
||||
import org.springframework.web.server.ContentTooLargeException;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
@@ -236,7 +236,7 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho
|
||||
|
||||
private Throwable handleReadError(MethodParameter parameter, Throwable ex) {
|
||||
if (ex instanceof DataBufferLimitException) {
|
||||
return new PayloadTooLargeException(ex);
|
||||
return new ContentTooLargeException(ex);
|
||||
}
|
||||
if (ex instanceof DecodingException) {
|
||||
return new ServerWebInputException("Failed to read HTTP message", parameter, ex);
|
||||
|
||||
+7
@@ -807,9 +807,16 @@ class CoRouterFunctionDsl internal constructor (private val init: (CoRouterFunct
|
||||
*/
|
||||
fun notFound() = ServerResponse.notFound()
|
||||
|
||||
/**
|
||||
* @see ServerResponse.unprocessableContent
|
||||
*/
|
||||
fun unprocessableContent() = ServerResponse.unprocessableContent()
|
||||
|
||||
/**
|
||||
* @see ServerResponse.unprocessableEntity
|
||||
*/
|
||||
@Deprecated("Use unprocessable content instead.", ReplaceWith("unprocessableContent()"))
|
||||
@Suppress("DEPRECATION")
|
||||
fun unprocessableEntity() = ServerResponse.unprocessableEntity()
|
||||
|
||||
/**
|
||||
|
||||
+11
@@ -870,12 +870,23 @@ class RouterFunctionDsl internal constructor (private val init: RouterFunctionDs
|
||||
fun notFound(): ServerResponse.HeadersBuilder<*> =
|
||||
ServerResponse.notFound()
|
||||
|
||||
/**
|
||||
* Create a builder with an
|
||||
* [422 Unprocessable Content][HttpStatus.UNPROCESSABLE_CONTENT] status.
|
||||
* @return the created builder
|
||||
* @since 7.0
|
||||
*/
|
||||
fun unprocessableContent(): ServerResponse.BodyBuilder =
|
||||
ServerResponse.unprocessableContent()
|
||||
|
||||
/**
|
||||
* Create a builder with an
|
||||
* [422 Unprocessable Entity][HttpStatus.UNPROCESSABLE_ENTITY] status.
|
||||
* @return the created builder
|
||||
* @since 5.1
|
||||
*/
|
||||
@Deprecated("Use unprocessable content instead.", ReplaceWith("unprocessableContent()"))
|
||||
@Suppress("DEPRECATION")
|
||||
fun unprocessableEntity(): ServerResponse.BodyBuilder =
|
||||
ServerResponse.unprocessableEntity()
|
||||
|
||||
|
||||
+2
-2
@@ -52,7 +52,7 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.support.ConfigurableWebBindingInitializer;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.reactive.BindingContext;
|
||||
import org.springframework.web.server.PayloadTooLargeException;
|
||||
import org.springframework.web.server.ContentTooLargeException;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.server.ServerWebInputException;
|
||||
import org.springframework.web.server.UnsupportedMediaTypeStatusException;
|
||||
@@ -128,7 +128,7 @@ class MessageReaderArgumentResolverTests {
|
||||
Mono<TestBean> result = (Mono<TestBean>) this.resolver.readBody(
|
||||
param, true, this.bindingContext, exchange).block();
|
||||
|
||||
StepVerifier.create(result).expectError(PayloadTooLargeException.class).verify();
|
||||
StepVerifier.create(result).expectError(ContentTooLargeException.class).verify();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
@@ -135,6 +135,7 @@ class ResponseEntityExceptionHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void handleResponseStatusException() {
|
||||
testException(new ResponseStatusException(HttpStatus.BANDWIDTH_LIMIT_EXCEEDED));
|
||||
}
|
||||
|
||||
+12
-1
@@ -213,9 +213,20 @@ public interface ServerResponse {
|
||||
|
||||
/**
|
||||
* Create a builder with a
|
||||
* {@linkplain HttpStatus#UNPROCESSABLE_ENTITY 422 Unprocessable Entity} status.
|
||||
* {@linkplain HttpStatus#UNPROCESSABLE_CONTENT 422 Unprocessable Content} status.
|
||||
* @return the created builder
|
||||
*/
|
||||
static BodyBuilder unprocessableContent() {
|
||||
return status(HttpStatus.UNPROCESSABLE_CONTENT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a builder with a
|
||||
* {@linkplain HttpStatus#UNPROCESSABLE_ENTITY 422 Unprocessable Entity} status.
|
||||
* @return the created builder
|
||||
* @deprecated since 7.0 in favor of {@link #unprocessableContent()}
|
||||
*/
|
||||
@Deprecated(since = "7.0")
|
||||
static BodyBuilder unprocessableEntity() {
|
||||
return status(HttpStatus.UNPROCESSABLE_ENTITY);
|
||||
}
|
||||
|
||||
+7
@@ -812,9 +812,16 @@ class RouterFunctionDsl internal constructor (private val init: (RouterFunctionD
|
||||
*/
|
||||
fun notFound() = ServerResponse.notFound()
|
||||
|
||||
/**
|
||||
* @see ServerResponse.unprocessableContent
|
||||
*/
|
||||
fun unprocessableContent() = ServerResponse.unprocessableContent()
|
||||
|
||||
/**
|
||||
* @see ServerResponse.unprocessableEntity
|
||||
*/
|
||||
@Deprecated("Use Unprocessable Content instead", ReplaceWith("unprocessableContent()"))
|
||||
@Suppress("DEPRECATION")
|
||||
fun unprocessableEntity() = ServerResponse.unprocessableEntity()
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user