Skip to content

Commit

Permalink
Reconsider akka-http -> pekko-http versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Dec 3, 2023
1 parent 36e529a commit faf190c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ class PekkoHttpGenerator private (pekkoHttpVersion: PekkoHttpVersion, modelGener
(
413,
pekkoHttpVersion match {
case PekkoHttpVersion.V10_1 => q"RequestEntityTooLarge"
case PekkoHttpVersion.V10_2 => q"PayloadTooLarge"
case PekkoHttpVersion.V1_0_0 => q"PayloadTooLarge"
case PekkoHttpVersion.V1_1_0 => q"ContentTooLarge"
}
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -804,19 +804,12 @@ class PekkoHttpServerGenerator private (pekkoHttpVersion: PekkoHttpVersion, mode
part.entity.dataBytes.toMat(fileSink)(Keep.right).run()
.transform(${Term.PartialFunction(
List(
if (pekkoHttpVersion == PekkoHttpVersion.V10_1)
Some(p"""
case IOResult(_, Failure(t)) =>
dest.delete()
throw t
""")
else None,
Some(p"""
p"""
case IOResult(_, _) =>
val hash = messageDigest.map(md => javax.xml.bind.DatatypeConverter.printHexBinary(md.digest()).toLowerCase(java.util.Locale.US))
(dest, part.filename, part.entity.contentType, hash)
""")
).flatten
"""
)
)}, { case t =>
dest.delete()
t
Expand All @@ -842,8 +835,8 @@ class PekkoHttpServerGenerator private (pekkoHttpVersion: PekkoHttpVersion, mode
}
val info = new ErrorInfo(summary, "Consider increasing the value of pekko.http.server.parsing.max-content-length")
val status = ${pekkoHttpVersion match {
case PekkoHttpVersion.V10_1 => q"StatusCodes.RequestEntityTooLarge"
case PekkoHttpVersion.V10_2 => q"StatusCodes.PayloadTooLarge"
case PekkoHttpVersion.V1_0_0 => q"StatusCodes.PayloadTooLarge"
case PekkoHttpVersion.V1_1_0 => q"StatusCodes.ContentTooLarge"
}}
val msg = if (settings.verboseErrorMessages) info.formatPretty else info.summary
complete(HttpResponse(status, entity = msg))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package dev.guardrail.generators.scala.pekkoHttp

sealed abstract class PekkoHttpVersion(val value: String)
object PekkoHttpVersion {
case object V10_1 extends PekkoHttpVersion("pekko-http-v10.1")
case object V10_2 extends PekkoHttpVersion("pekko-http-v10.2")
case object V1_0_0 extends PekkoHttpVersion("pekko-http-v1.0.0")
case object V1_1_0 extends PekkoHttpVersion("pekko-http-v1.1.0")

val mapping: Map[String, PekkoHttpVersion] = Map(
"pekko-http" -> V10_2,
V10_1.value -> V10_1,
V10_2.value -> V10_2
"pekko-http" -> V1_1_0,
V1_0_0.value -> V1_0_0,
V1_1_0.value -> V1_1_0
)
}

0 comments on commit faf190c

Please sign in to comment.