Skip to content

Commit

Permalink
Merge pull request #3116 from softwaremill/pekko-scala3
Browse files Browse the repository at this point in the history
Enable pekko for Scala 3
  • Loading branch information
adamw authored Aug 17, 2023
2 parents 36ddf6e + 55fc977 commit 46655de
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ lazy val pekkoHttpServer: ProjectMatrix = (projectMatrix in file("server/pekko-h
"com.softwaremill.sttp.client3" %% "pekko-http-backend" % Versions.sttp % Test
)
)
.jvmPlatform(scalaVersions = scala2Versions)
.jvmPlatform(scalaVersions = scala2And3Versions)
.dependsOn(serverCore, serverTests % Test)

lazy val akkaGrpcServer: ProjectMatrix = (projectMatrix in file("server/akka-grpc-server"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package sttp.tapir.server.pekkohttp

import org.apache.pekko.http.scaladsl.server.RequestContext
import org.apache.pekko.http.scaladsl.model.headers.{`Content-Length`, `Content-Type`}
import org.apache.pekko.http.scaladsl.model.{Uri => PekkoUri}
import sttp.model.{Header, Method, QueryParams, Uri}
import sttp.model.{Header, HeaderNames, Method, QueryParams, Uri}
import sttp.tapir.{AttributeKey, AttributeMap}
import sttp.tapir.model.{ConnectionInfo, ServerRequest}

Expand All @@ -20,7 +19,7 @@ private[pekkohttp] case class PekkoServerRequest(ctx: RequestContext, attributes
def run(p: PekkoUri.Path, acc: List[String]): List[String] = p match {
case PekkoUri.Path.Slash(pathTail) => run(pathTail, acc)
case PekkoUri.Path.Segment(s, pathTail) => run(pathTail, s :: acc)
case _ => acc.reverse
case _ => acc.reverse
}

run(ctx.unmatchedPath, Nil)
Expand All @@ -35,14 +34,16 @@ private[pekkohttp] case class PekkoServerRequest(ctx: RequestContext, attributes
// https://doc.pekko.io/docs/pekko-http/current/common/http-model.html?language=scala#http-headers
// https://github.com/softwaremill/tapir/issues/331
override lazy val headers: Seq[Header] = {
val contentLength = ctx.request.entity.contentLengthOption.map(`Content-Length`(_))
val contentType = `Content-Type`(ctx.request.entity.contentType)
val pekkoHeaders = contentType :: contentLength.toList ++ ctx.request.headers
pekkoHeaders.filterNot(_.value == EmptyContentType).map(h => Header(h.name(), h.value()))
val contentLengthHeader = ctx.request.entity.contentLengthOption.map(cl => Header(HeaderNames.ContentLength, cl.toString))
val contentType = ctx.request.entity.contentType.value
val contentTypeHeader =
if (contentType == EmptyContentType) Nil else List(Header(HeaderNames.ContentType, ctx.request.entity.contentType.value))
contentTypeHeader ++ contentLengthHeader.toList ++ ctx.request.headers.map(h => Header(h.name(), h.value()))
}

override def attribute[T](k: AttributeKey[T]): Option[T] = attributes.get(k)
override def attribute[T](k: AttributeKey[T], v: T): PekkoServerRequest = copy(attributes = attributes.put(k, v))

override def withUnderlying(underlying: Any): ServerRequest = PekkoServerRequest(ctx = underlying.asInstanceOf[RequestContext], attributes)
override def withUnderlying(underlying: Any): ServerRequest =
PekkoServerRequest(ctx = underlying.asInstanceOf[RequestContext], attributes)
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private[pekkohttp] class PekkoToResponseBody(implicit m: Materializer, ec: Execu
case m: RawBodyType.MultipartBody =>
val parts = (r: Seq[RawPart]).flatMap(rawPartToBodyPart(m, _))
val body = Multipart.FormData(parts: _*)
body.toEntity()
body.toEntity
}
}

Expand Down

0 comments on commit 46655de

Please sign in to comment.