Skip to content

Commit d474334

Browse files
authored
Update naming for status codes 413 and 422 (#87)
1 parent 8b6ec62 commit d474334

File tree

13 files changed

+46
-27
lines changed

13 files changed

+46
-27
lines changed

docs/src/test/java/docs/http/javadsl/server/directives/MiscDirectivesExamplesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public void testWithSizeLimit() {
9393

9494
testRoute(route)
9595
.run(withEntityOfSize.apply(501))
96-
.assertStatusCode(StatusCodes.PAYLOAD_TOO_LARGE);
96+
.assertStatusCode(StatusCodes.CONTENT_TOO_LARGE);
9797
// #withSizeLimitExample
9898
}
9999

@@ -119,7 +119,7 @@ public void testWithSizeLimitNested() {
119119

120120
testRoute(route)
121121
.run(withEntityOfSize.apply(801))
122-
.assertStatusCode(StatusCodes.PAYLOAD_TOO_LARGE);
122+
.assertStatusCode(StatusCodes.CONTENT_TOO_LARGE);
123123
// #withSizeLimitExampleNested
124124
}
125125

docs/src/test/scala/docs/http/scaladsl/server/directives/MiscDirectivesExamplesSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ class MiscDirectivesExamplesSpec extends RoutingSpec with CompileOnlySpec {
139139
}
140140

141141
Post("/abc", entityOfSize(501)) ~> Route.seal(route) ~> check {
142-
status shouldEqual StatusCodes.PayloadTooLarge
142+
status shouldEqual StatusCodes.ContentTooLarge
143143
}
144144

145145
// #withSizeLimit-example
@@ -184,7 +184,7 @@ class MiscDirectivesExamplesSpec extends RoutingSpec with CompileOnlySpec {
184184
}
185185

186186
Post("/abc", entityOfSize(801)) ~> Route.seal(route) ~> check {
187-
status shouldEqual StatusCodes.PayloadTooLarge
187+
status shouldEqual StatusCodes.ContentTooLarge
188188
}
189189
// #withSizeLimit-nested-example
190190
}

http-core/src/main/java/org/apache/pekko/http/javadsl/model/StatusCodes.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,19 @@ private StatusCodes() {}
9797
org.apache.pekko.http.scaladsl.model.StatusCodes.LengthRequired();
9898
public static final StatusCode PRECONDITION_FAILED =
9999
org.apache.pekko.http.scaladsl.model.StatusCodes.PreconditionFailed();
100+
101+
public static final StatusCode CONTENT_TOO_LARGE =
102+
org.apache.pekko.http.scaladsl.model.StatusCodes.ContentTooLarge();
103+
104+
/** @deprecated deprecated in favor of CONTENT_TOO_LARGE since 1.1.0 */
105+
@Deprecated
100106
public static final StatusCode PAYLOAD_TOO_LARGE =
101107
org.apache.pekko.http.scaladsl.model.StatusCodes.PayloadTooLarge();
102108

103-
/** @deprecated deprecated in favor of PAYLOAD_TOO_LARGE */
109+
/**
110+
* @deprecated deprecated in favor of PAYLOAD_TOO_LARGE, which was later deprecated in favor of
111+
* CONTENT_TOO_LARGE (please switch to CONTENT_TOO_LARGE)
112+
*/
104113
@Deprecated
105114
public static final StatusCode REQUEST_ENTITY_TOO_LARGE =
106115
org.apache.pekko.http.scaladsl.model.StatusCodes.RequestEntityTooLarge();
@@ -131,8 +140,14 @@ private StatusCodes() {}
131140
org.apache.pekko.http.scaladsl.model.StatusCodes.EnhanceYourCalm();
132141
public static final StatusCode MISDIRECTED_REQUEST =
133142
org.apache.pekko.http.scaladsl.model.StatusCodes.MisdirectedRequest();
143+
public static final StatusCode UNPROCESSABLE_CONTENT =
144+
org.apache.pekko.http.scaladsl.model.StatusCodes.UnprocessableContent();
145+
146+
/** @deprecated deprecated in favor of UNPROCESSABLE_CONTENT since 1.1.0 */
147+
@Deprecated
134148
public static final StatusCode UNPROCESSABLE_ENTITY =
135149
org.apache.pekko.http.scaladsl.model.StatusCodes.UnprocessableEntity();
150+
136151
public static final StatusCode LOCKED = org.apache.pekko.http.scaladsl.model.StatusCodes.Locked();
137152
public static final StatusCode FAILED_DEPENDENCY =
138153
org.apache.pekko.http.scaladsl.model.StatusCodes.FailedDependency();

http-core/src/main/scala/org/apache/pekko/http/impl/engine/parsing/HttpRequestParser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private[http] final class HttpRequestParser(
228228
setCompletionHandling(HttpMessageParser.CompletionOk)
229229
startNewMessage(input, bodyStart)
230230
} else if (!method.isEntityAccepted) {
231-
failMessageStart(UnprocessableEntity, s"${method.name} requests must not have an entity")
231+
failMessageStart(UnprocessableContent, s"${method.name} requests must not have an entity")
232232
} else if (contentLength <= input.size - bodyStart) {
233233
val cl = contentLength.toInt
234234
emitRequestStart(strictEntity(cth, input, bodyStart, cl))
@@ -240,7 +240,7 @@ private[http] final class HttpRequestParser(
240240
}
241241
} else {
242242
if (!method.isEntityAccepted) {
243-
failMessageStart(UnprocessableEntity, s"${method.name} requests must not have an entity")
243+
failMessageStart(UnprocessableContent, s"${method.name} requests must not have an entity")
244244
} else {
245245
if (clh.isEmpty) {
246246
emitRequestStart(chunkedEntity(cth), headers)

http-core/src/main/scala/org/apache/pekko/http/impl/engine/server/HttpServerBluePrint.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ private[http] object HttpServerBluePrint {
546546
}
547547
val info =
548548
ErrorInfo(summary, "Consider increasing the value of pekko.http.server.parsing.max-content-length")
549-
finishWithIllegalRequestError(StatusCodes.PayloadTooLarge, info)
549+
finishWithIllegalRequestError(StatusCodes.ContentTooLarge, info)
550550

551551
case IllegalUriException(errorInfo) =>
552552
finishWithIllegalRequestError(StatusCodes.BadRequest, errorInfo)

http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/StatusCode.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,11 @@ object StatusCodes extends ObjectRegistry[Int, StatusCode] {
151151
val Gone = reg(c(410)("Gone", "The resource requested is no longer available and will not be available again."))
152152
val LengthRequired = reg(c(411)("Length Required", "The request did not specify the length of its content, which is required by the requested resource."))
153153
val PreconditionFailed = reg(c(412)("Precondition Failed", "The server does not meet one of the preconditions that the requester put on the request."))
154-
val PayloadTooLarge = reg(c(413)("Payload Too Large", "The request payload is larger than the server is willing or able to process."))
155-
@deprecated("deprecated in favor of PayloadTooLarge", "Akka HTTP 10.1.11")
156-
val RequestEntityTooLarge = PayloadTooLarge
154+
val ContentTooLarge = reg(c(413)("Content Too Large", "The request content is larger than the server is willing or able to process."))
155+
@deprecated("deprecated in favor of ContentTooLarge", "1.1.0")
156+
val PayloadTooLarge = ContentTooLarge
157+
@deprecated("deprecated in favor of PayloadTooLarge, which was later deprecated in favor of ContentTooLarge (please switch to ContentTooLarge)", "Akka HTTP 10.1.11")
158+
val RequestEntityTooLarge = ContentTooLarge
157159
val UriTooLong = reg(c(414)("URI Too Long", "The URI provided was too long for the server to process."))
158160
@deprecated("deprecated in favor of UriTooLong", "Akka HTTP 10.1.11")
159161
val RequestUriTooLong = UriTooLong
@@ -165,7 +167,9 @@ object StatusCodes extends ObjectRegistry[Int, StatusCode] {
165167
val ImATeapot = reg(c(418)("I'm a teapot", "The resulting entity body MAY be short and stout."))
166168
val EnhanceYourCalm = reg(c(420)("Enhance Your Calm", "You are being rate-limited.")) // Twitter only
167169
val MisdirectedRequest = reg(c(421)("Misdirected Request", "The request was directed at a server that is not able to produce a response.")) // HTTP/2 only. https://tools.ietf.org/html/rfc7540#section-9.1.2
168-
val UnprocessableEntity = reg(c(422)("Unprocessable Entity", "The request was well-formed but was unable to be followed due to semantic errors."))
170+
val UnprocessableContent = reg(c(422)("Unprocessable Content", "The request was well-formed but was unable to be followed due to semantic errors."))
171+
@deprecated("deprecated in favor of UnprocessableContent", "1.1.0")
172+
val UnprocessableEntity = UnprocessableContent
169173
val Locked = reg(c(423)("Locked", "The resource that is being accessed is locked."))
170174
val FailedDependency = reg(c(424)("Failed Dependency", "The request failed due to failure of a previous request."))
171175
val TooEarly = reg(c(425)("Too Early", "The server is unwilling to risk processing a request that might be replayed.")) // RFC 8470

http-core/src/test/scala/org/apache/pekko/http/impl/engine/server/HttpServerSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,7 +1394,7 @@ class HttpServerSpec extends PekkoSpec(
13941394
responses.sendError(error.asInstanceOf[Exception])
13951395

13961396
expectResponseWithWipedDate(
1397-
s"""HTTP/1.1 413 Payload Too Large
1397+
s"""HTTP/1.1 413 Content Too Large
13981398
|Server: pekko-http/test
13991399
|Date: XXXX
14001400
|Connection: close
@@ -1418,7 +1418,7 @@ class HttpServerSpec extends PekkoSpec(
14181418
responses.sendError(error.asInstanceOf[Exception])
14191419

14201420
expectResponseWithWipedDate(
1421-
s"""HTTP/1.1 413 Payload Too Large
1421+
s"""HTTP/1.1 413 Content Too Large
14221422
|Server: pekko-http/test
14231423
|Date: XXXX
14241424
|Connection: close

http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/MiscDirectivesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public void testWithSizeLimit() {
9999

100100
route.run(withEntityOfSize(500)).assertStatusCode(StatusCodes.OK);
101101

102-
route.run(withEntityOfSize(501)).assertStatusCode(StatusCodes.PAYLOAD_TOO_LARGE);
102+
route.run(withEntityOfSize(501)).assertStatusCode(StatusCodes.CONTENT_TOO_LARGE);
103103
}
104104

105105
private HttpRequest withEntityOfSize(int sizeLimit) {

http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/RouteDirectivesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void testEntitySizeLargerThanLimit() {
9797

9898
route
9999
.run(HttpRequest.create("/limit-5").withEntity("1234567890"))
100-
.assertStatusCode(StatusCodes.PAYLOAD_TOO_LARGE)
100+
.assertStatusCode(StatusCodes.CONTENT_TOO_LARGE)
101101
.assertEntity(
102102
"EntityStreamSizeException: incoming entity size (10) exceeded size limit (5 bytes)! "
103103
+ "This may have been a parser limit (set via `pekko.http.[server|client].parsing.max-content-length`), "

http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/SizeLimitSpec.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SizeLimitSpec extends AnyWordSpec with Matchers with RequestBuilding with
7878

7979
"not accept entities bigger than configured with pekko.http.parsing.max-content-length" in {
8080
Http().singleRequest(Post(s"http:/${binding.localAddress}/noDirective", entityOfSize(maxContentLength + 1)))
81-
.futureValue.status shouldEqual StatusCodes.PayloadTooLarge
81+
.futureValue.status shouldEqual StatusCodes.ContentTooLarge
8282
}
8383
}
8484

@@ -116,7 +116,7 @@ class SizeLimitSpec extends AnyWordSpec with Matchers with RequestBuilding with
116116
data.size should be > decodeMaxSize
117117

118118
Http().singleRequest(request)
119-
.futureValue.status shouldEqual StatusCodes.PayloadTooLarge
119+
.futureValue.status shouldEqual StatusCodes.ContentTooLarge
120120
}
121121
}
122122

@@ -139,7 +139,7 @@ class SizeLimitSpec extends AnyWordSpec with Matchers with RequestBuilding with
139139
val request =
140140
Post(s"http:/${binding.localAddress}/noDirective", "x").withHeaders(`Content-Encoding`(HttpEncoding("custom")))
141141
val response = Http().singleRequest(request).futureValue
142-
response.status shouldEqual StatusCodes.PayloadTooLarge
142+
response.status shouldEqual StatusCodes.ContentTooLarge
143143
}
144144
}
145145

@@ -162,7 +162,7 @@ class SizeLimitSpec extends AnyWordSpec with Matchers with RequestBuilding with
162162
val request =
163163
Post(s"http:/${binding.localAddress}/noDirective", "x").withHeaders(`Content-Encoding`(HttpEncoding("custom")))
164164
val response = Http().singleRequest(request).futureValue
165-
response.status shouldEqual StatusCodes.PayloadTooLarge
165+
response.status shouldEqual StatusCodes.ContentTooLarge
166166
}
167167
}
168168

0 commit comments

Comments
 (0)