Skip to content

Commit

Permalink
Update naming for status codes 413 and 422
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippus committed Feb 26, 2023
1 parent acd0f83 commit 3ff3fa4
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void testWithSizeLimit() {

route
.run(withEntityOfSize(501))
.assertStatusCode(StatusCodes.PAYLOAD_TOO_LARGE);
.assertStatusCode(StatusCodes.CONTENT_TOO_LARGE);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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`), " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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
}
}

Expand All @@ -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
}
}

Expand All @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand All @@ -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)! " +
Expand All @@ -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")
}

Expand All @@ -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")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down

0 comments on commit 3ff3fa4

Please sign in to comment.