diff --git a/docs/src/test/java/docs/http/javadsl/server/directives/MiscDirectivesExamplesTest.java b/docs/src/test/java/docs/http/javadsl/server/directives/MiscDirectivesExamplesTest.java index 47aae4b70..6246aff2d 100644 --- a/docs/src/test/java/docs/http/javadsl/server/directives/MiscDirectivesExamplesTest.java +++ b/docs/src/test/java/docs/http/javadsl/server/directives/MiscDirectivesExamplesTest.java @@ -95,7 +95,7 @@ public void testWithSizeLimit() { .assertStatusCode(StatusCodes.OK); testRoute(route).run(withEntityOfSize.apply(501)) - .assertStatusCode(StatusCodes.PAYLOAD_TOO_LARGE); + .assertStatusCode(StatusCodes.CONTENT_TOO_LARGE); //#withSizeLimitExample } @@ -120,7 +120,7 @@ public void testWithSizeLimitNested() { .assertStatusCode(StatusCodes.OK); testRoute(route).run(withEntityOfSize.apply(801)) - .assertStatusCode(StatusCodes.PAYLOAD_TOO_LARGE); + .assertStatusCode(StatusCodes.CONTENT_TOO_LARGE); //#withSizeLimitExampleNested } diff --git a/docs/src/test/scala/docs/http/scaladsl/server/directives/MiscDirectivesExamplesSpec.scala b/docs/src/test/scala/docs/http/scaladsl/server/directives/MiscDirectivesExamplesSpec.scala index 98c0c2de3..ff104d2be 100644 --- a/docs/src/test/scala/docs/http/scaladsl/server/directives/MiscDirectivesExamplesSpec.scala +++ b/docs/src/test/scala/docs/http/scaladsl/server/directives/MiscDirectivesExamplesSpec.scala @@ -138,7 +138,7 @@ class MiscDirectivesExamplesSpec extends RoutingSpec with CompileOnlySpec { } Post("/abc", entityOfSize(501)) ~> Route.seal(route) ~> check { - status shouldEqual StatusCodes.PayloadTooLarge + status shouldEqual StatusCodes.ContentTooLarge } // #withSizeLimit-example @@ -183,7 +183,7 @@ class MiscDirectivesExamplesSpec extends RoutingSpec with CompileOnlySpec { } Post("/abc", entityOfSize(801)) ~> Route.seal(route) ~> check { - status shouldEqual StatusCodes.PayloadTooLarge + status shouldEqual StatusCodes.ContentTooLarge } // #withSizeLimit-nested-example } diff --git a/http-core/src/main/java/org/apache/pekko/http/javadsl/model/StatusCodes.java b/http-core/src/main/java/org/apache/pekko/http/javadsl/model/StatusCodes.java index 09163a414..5dbccf7f6 100644 --- a/http-core/src/main/java/org/apache/pekko/http/javadsl/model/StatusCodes.java +++ b/http-core/src/main/java/org/apache/pekko/http/javadsl/model/StatusCodes.java @@ -66,10 +66,16 @@ private StatusCodes() {} public static final StatusCode GONE = org.apache.pekko.http.scaladsl.model.StatusCodes.Gone(); public static final StatusCode LENGTH_REQUIRED = org.apache.pekko.http.scaladsl.model.StatusCodes.LengthRequired(); public static final StatusCode PRECONDITION_FAILED = org.apache.pekko.http.scaladsl.model.StatusCodes.PreconditionFailed(); + public static final StatusCode CONTENT_TOO_LARGE = org.apache.pekko.http.scaladsl.model.StatusCodes.ContentTooLarge(); + + /** + * @deprecated deprecated in favor of CONTENT_TOO_LARGE + */ + @Deprecated public static final StatusCode PAYLOAD_TOO_LARGE = org.apache.pekko.http.scaladsl.model.StatusCodes.PayloadTooLarge(); /** - * @deprecated deprecated in favor of PAYLOAD_TOO_LARGE + * @deprecated deprecated in favor of CONTENT_TOO_LARGE */ @Deprecated public static final StatusCode REQUEST_ENTITY_TOO_LARGE = org.apache.pekko.http.scaladsl.model.StatusCodes.RequestEntityTooLarge(); @@ -92,6 +98,12 @@ private StatusCodes() {} public static final StatusCode IM_A_TEAPOT = org.apache.pekko.http.scaladsl.model.StatusCodes.ImATeapot(); public static final StatusCode ENHANCE_YOUR_CALM = org.apache.pekko.http.scaladsl.model.StatusCodes.EnhanceYourCalm(); public static final StatusCode MISDIRECTED_REQUEST = org.apache.pekko.http.scaladsl.model.StatusCodes.MisdirectedRequest(); + public static final StatusCode UNPROCESSABLE_CONTENT = org.apache.pekko.http.scaladsl.model.StatusCodes.UnprocessableContent(); + + /** + * @deprecated deprecated in favor of UNPROCESSABLE_CONTENT + */ + @Deprecated public static final StatusCode UNPROCESSABLE_ENTITY = org.apache.pekko.http.scaladsl.model.StatusCodes.UnprocessableEntity(); public static final StatusCode LOCKED = org.apache.pekko.http.scaladsl.model.StatusCodes.Locked(); public static final StatusCode FAILED_DEPENDENCY = org.apache.pekko.http.scaladsl.model.StatusCodes.FailedDependency(); diff --git a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/parsing/HttpRequestParser.scala b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/parsing/HttpRequestParser.scala index 8203235f4..2b3e50c6e 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/parsing/HttpRequestParser.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/parsing/HttpRequestParser.scala @@ -228,7 +228,7 @@ private[http] final class HttpRequestParser( setCompletionHandling(HttpMessageParser.CompletionOk) startNewMessage(input, bodyStart) } else if (!method.isEntityAccepted) { - failMessageStart(UnprocessableEntity, s"${method.name} requests must not have an entity") + failMessageStart(UnprocessableContent, s"${method.name} requests must not have an entity") } else if (contentLength <= input.size - bodyStart) { val cl = contentLength.toInt emitRequestStart(strictEntity(cth, input, bodyStart, cl)) @@ -240,7 +240,7 @@ private[http] final class HttpRequestParser( } } else { if (!method.isEntityAccepted) { - failMessageStart(UnprocessableEntity, s"${method.name} requests must not have an entity") + failMessageStart(UnprocessableContent, s"${method.name} requests must not have an entity") } else { if (clh.isEmpty) { emitRequestStart(chunkedEntity(cth), headers) diff --git a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/server/HttpServerBluePrint.scala b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/server/HttpServerBluePrint.scala index 8dbb92c28..0484c874f 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/impl/engine/server/HttpServerBluePrint.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/impl/engine/server/HttpServerBluePrint.scala @@ -546,7 +546,7 @@ private[http] object HttpServerBluePrint { } val info = ErrorInfo(summary, "Consider increasing the value of pekko.http.server.parsing.max-content-length") - finishWithIllegalRequestError(StatusCodes.PayloadTooLarge, info) + finishWithIllegalRequestError(StatusCodes.ContentTooLarge, info) case IllegalUriException(errorInfo) => finishWithIllegalRequestError(StatusCodes.BadRequest, errorInfo) diff --git a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/StatusCode.scala b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/StatusCode.scala index 081d9005e..4ce322651 100644 --- a/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/StatusCode.scala +++ b/http-core/src/main/scala/org/apache/pekko/http/scaladsl/model/StatusCode.scala @@ -151,9 +151,11 @@ object StatusCodes extends ObjectRegistry[Int, StatusCode] { val Gone = reg(c(410)("Gone", "The resource requested is no longer available and will not be available again.")) val LengthRequired = reg(c(411)("Length Required", "The request did not specify the length of its content, which is required by the requested resource.")) val PreconditionFailed = reg(c(412)("Precondition Failed", "The server does not meet one of the preconditions that the requester put on the request.")) - val PayloadTooLarge = reg(c(413)("Payload Too Large", "The request payload is larger than the server is willing or able to process.")) - @deprecated("deprecated in favor of PayloadTooLarge", "Akka HTTP 10.1.11") - val RequestEntityTooLarge = PayloadTooLarge + val ContentTooLarge = reg(c(413)("Content Too Large", "The request content is larger than the server is willing or able to process.")) + @deprecated("deprecated in favor of ContentTooLarge", "1.0.0") + val PayloadTooLarge = ContentTooLarge + @deprecated("deprecated in favor of ContentTooLarge", "1.0.0") + val RequestEntityTooLarge = ContentTooLarge val UriTooLong = reg(c(414)("URI Too Long", "The URI provided was too long for the server to process.")) @deprecated("deprecated in favor of UriTooLong", "Akka HTTP 10.1.11") val RequestUriTooLong = UriTooLong @@ -165,7 +167,9 @@ object StatusCodes extends ObjectRegistry[Int, StatusCode] { val ImATeapot = reg(c(418)("I'm a teapot", "The resulting entity body MAY be short and stout.")) val EnhanceYourCalm = reg(c(420)("Enhance Your Calm", "You are being rate-limited.")) // Twitter only 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 - val UnprocessableEntity = reg(c(422)("Unprocessable Entity", "The request was well-formed but was unable to be followed due to semantic errors.")) + val UnprocessableContent = reg(c(422)("Unprocessable Content", "The request was well-formed but was unable to be followed due to semantic errors.")) + @deprecated("deprecated in favor of UnprocessableContent", "1.0.0") + val UnprocessableEntity = UnprocessableContent val Locked = reg(c(423)("Locked", "The resource that is being accessed is locked.")) val FailedDependency = reg(c(424)("Failed Dependency", "The request failed due to failure of a previous request.")) val TooEarly = reg(c(425)("Too Early", "The server is unwilling to risk processing a request that might be replayed.")) // RFC 8470 diff --git a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/server/HttpServerSpec.scala b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/server/HttpServerSpec.scala index 40f53d52e..a924344c1 100644 --- a/http-core/src/test/scala/org/apache/pekko/http/impl/engine/server/HttpServerSpec.scala +++ b/http-core/src/test/scala/org/apache/pekko/http/impl/engine/server/HttpServerSpec.scala @@ -1393,7 +1393,7 @@ class HttpServerSpec extends PekkoSpec( responses.sendError(error.asInstanceOf[Exception]) expectResponseWithWipedDate( - s"""HTTP/1.1 413 Payload Too Large + s"""HTTP/1.1 413 Content Too Large |Server: pekko-http/test |Date: XXXX |Connection: close @@ -1417,7 +1417,7 @@ class HttpServerSpec extends PekkoSpec( responses.sendError(error.asInstanceOf[Exception]) expectResponseWithWipedDate( - s"""HTTP/1.1 413 Payload Too Large + s"""HTTP/1.1 413 Content Too Large |Server: pekko-http/test |Date: XXXX |Connection: close diff --git a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/MiscDirectivesTest.java b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/MiscDirectivesTest.java index b70c5b904..f7e45cdab 100644 --- a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/MiscDirectivesTest.java +++ b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/MiscDirectivesTest.java @@ -97,7 +97,7 @@ public void testWithSizeLimit() { route .run(withEntityOfSize(501)) - .assertStatusCode(StatusCodes.PAYLOAD_TOO_LARGE); + .assertStatusCode(StatusCodes.CONTENT_TOO_LARGE); } diff --git a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/RouteDirectivesTest.java b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/RouteDirectivesTest.java index 28e69adba..fd8202aee 100644 --- a/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/RouteDirectivesTest.java +++ b/http-tests/src/test/java/org/apache/pekko/http/javadsl/server/directives/RouteDirectivesTest.java @@ -98,7 +98,7 @@ public void testEntitySizeLargerThanLimit() { route .run(HttpRequest.create("/limit-5").withEntity("1234567890")) - .assertStatusCode(StatusCodes.PAYLOAD_TOO_LARGE) + .assertStatusCode(StatusCodes.CONTENT_TOO_LARGE) .assertEntity("EntityStreamSizeException: incoming entity size (10) exceeded size limit (5 bytes)! " + "This may have been a parser limit (set via `pekko.http.[server|client].parsing.max-content-length`), " + "a decoder limit (set via `pekko.http.routing.decode-max-size`), " + diff --git a/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/SizeLimitSpec.scala b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/SizeLimitSpec.scala index 5b14d4a1c..b463e9344 100644 --- a/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/SizeLimitSpec.scala +++ b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/SizeLimitSpec.scala @@ -76,7 +76,7 @@ class SizeLimitSpec extends AnyWordSpec with Matchers with RequestBuilding with "not accept entities bigger than configured with pekko.http.parsing.max-content-length" in { Http().singleRequest(Post(s"http:/${binding.localAddress}/noDirective", entityOfSize(maxContentLength + 1))) - .futureValue.status shouldEqual StatusCodes.PayloadTooLarge + .futureValue.status shouldEqual StatusCodes.ContentTooLarge } } @@ -114,7 +114,7 @@ class SizeLimitSpec extends AnyWordSpec with Matchers with RequestBuilding with data.size should be > decodeMaxSize Http().singleRequest(request) - .futureValue.status shouldEqual StatusCodes.PayloadTooLarge + .futureValue.status shouldEqual StatusCodes.ContentTooLarge } } @@ -137,7 +137,7 @@ class SizeLimitSpec extends AnyWordSpec with Matchers with RequestBuilding with val request = Post(s"http:/${binding.localAddress}/noDirective", "x").withHeaders(`Content-Encoding`(HttpEncoding("custom"))) val response = Http().singleRequest(request).futureValue - response.status shouldEqual StatusCodes.PayloadTooLarge + response.status shouldEqual StatusCodes.ContentTooLarge } } @@ -160,7 +160,7 @@ class SizeLimitSpec extends AnyWordSpec with Matchers with RequestBuilding with val request = Post(s"http:/${binding.localAddress}/noDirective", "x").withHeaders(`Content-Encoding`(HttpEncoding("custom"))) val response = Http().singleRequest(request).futureValue - response.status shouldEqual StatusCodes.PayloadTooLarge + response.status shouldEqual StatusCodes.ContentTooLarge } } diff --git a/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/directives/MiscDirectivesSpec.scala b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/directives/MiscDirectivesSpec.scala index fd3c4be4b..9fa5a40c9 100644 --- a/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/directives/MiscDirectivesSpec.scala +++ b/http-tests/src/test/scala/org/apache/pekko/http/scaladsl/server/directives/MiscDirectivesSpec.scala @@ -115,7 +115,7 @@ class MiscDirectivesSpec extends RoutingSpec { } Post("/abc", entityOfSize(501)) ~> Route.seal(route) ~> check { - status shouldEqual StatusCodes.PayloadTooLarge + status shouldEqual StatusCodes.ContentTooLarge entityAs[String] should include("exceeded size limit") } } @@ -133,7 +133,7 @@ class MiscDirectivesSpec extends RoutingSpec { } Post("/abc", formDataOfSize(128)) ~> Route.seal(route) ~> check { - status shouldEqual StatusCodes.PayloadTooLarge + status shouldEqual StatusCodes.ContentTooLarge responseAs[String] shouldEqual "The request content was malformed:\n" + "EntityStreamSizeException: incoming entity size (134) " + "exceeded size limit (64 bytes)! " + @@ -158,7 +158,7 @@ class MiscDirectivesSpec extends RoutingSpec { } Post("/abc", entityOfSize(801)) ~> Route.seal(route) ~> check { - status shouldEqual StatusCodes.PayloadTooLarge + status shouldEqual StatusCodes.ContentTooLarge entityAs[String] should include("exceeded size limit") } @@ -176,7 +176,7 @@ class MiscDirectivesSpec extends RoutingSpec { } Post("/abc", entityOfSize(401)) ~> Route.seal(route2) ~> check { - status shouldEqual StatusCodes.PayloadTooLarge + status shouldEqual StatusCodes.ContentTooLarge entityAs[String] should include("exceeded size limit") } } diff --git a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/ExceptionHandler.scala b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/ExceptionHandler.scala index ce670488a..2d37f53d7 100644 --- a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/ExceptionHandler.scala +++ b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/ExceptionHandler.scala @@ -63,9 +63,9 @@ object ExceptionHandler { ctx.complete((status, info.format(settings.verboseErrorMessages))) } case e: EntityStreamSizeException => ctx => { - ctx.log.error(e, ErrorMessageTemplate, e, PayloadTooLarge) + ctx.log.error(e, ErrorMessageTemplate, e, ContentTooLarge) ctx.request.discardEntityBytes(ctx.materializer) - ctx.complete((PayloadTooLarge, e.getMessage)) + ctx.complete((ContentTooLarge, e.getMessage)) } case e: ExceptionWithErrorInfo => ctx => { ctx.log.error(e, ErrorMessageTemplate, e.info.formatPretty, InternalServerError) diff --git a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/RejectionHandler.scala b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/RejectionHandler.scala index 8e76e0188..a80238001 100644 --- a/http/src/main/scala/org/apache/pekko/http/scaladsl/server/RejectionHandler.scala +++ b/http/src/main/scala/org/apache/pekko/http/scaladsl/server/RejectionHandler.scala @@ -202,7 +202,7 @@ object RejectionHandler { case MalformedRequestContentRejection(msg, throwable) => { val rejectionMessage = "The request content was malformed:\n" + msg throwable match { - case _: EntityStreamSizeException => rejectRequestEntityAndComplete((PayloadTooLarge, rejectionMessage)) + case _: EntityStreamSizeException => rejectRequestEntityAndComplete((ContentTooLarge, rejectionMessage)) case _ => rejectRequestEntityAndComplete((BadRequest, rejectionMessage)) } }