Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable pekko for Scala 3 #3116

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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