Skip to content

Commit

Permalink
Merge branch 'main' into add-cookie-helper
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTriple authored Sep 25, 2023
2 parents 3179ba6 + 4123b17 commit 47a0fb4
Show file tree
Hide file tree
Showing 39 changed files with 591 additions and 355 deletions.
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ d338861916380701fb1a3cf557bb2b0f18792075

# Scala Steward: Reformat with scalafmt 3.7.3
9685d201c17c737cf4617ec648d76aff461bd831

# Scala Steward: Reformat with scalafmt 3.7.14
85133289bbd902a9fa5c13ff515eda5c0b58fd1d
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0

Expand Down
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.7.3
version = 3.7.14
maxColumn = 120

align.preset = more
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ lazy val zioHttpBenchmarks = (project in file("zio-http-benchmarks"))
"com.softwaremill.sttp.tapir" %% "tapir-json-circe" % "1.5.1",
"com.softwaremill.sttp.client3" %% "core" % "3.9.0",
// "dev.zio" %% "zio-interop-cats" % "3.3.0",
"org.slf4j" % "slf4j-api" % "2.0.7",
"org.slf4j" % "slf4j-simple" % "2.0.7",
"org.slf4j" % "slf4j-api" % "2.0.9",
"org.slf4j" % "slf4j-simple" % "2.0.9",
),
)
.dependsOn(zioHttp)
Expand Down
4 changes: 2 additions & 2 deletions profiling/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.1.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
2 changes: 1 addition & 1 deletion project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ object BuildHelper extends ScalaSettings {
scalacOptions := stdOptions ++ extraOptions(scalaVersion.value),
ThisBuild / scalafixDependencies ++=
List(
"com.github.vovapolu" %% "scaluzzi" % "0.1.23",
"com.github.vovapolu" %% "scaluzzi" % "0.1.23",
),
Test / parallelExecution := true,
incOptions ~= (_.withLogRecompileOnMacro(false)),
Expand Down
6 changes: 3 additions & 3 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import sbt.Keys.scalaVersion

object Dependencies {
val JwtCoreVersion = "9.1.1"
val NettyVersion = "4.1.93.Final"
val NettyVersion = "4.1.98.Final"
val NettyIncubatorVersion = "0.0.20.Final"
val ScalaCompactCollectionVersion = "2.11.0"
val ZioVersion = "2.0.16"
val ZioVersion = "2.0.17"
val ZioCliVersion = "0.5.0"
val ZioSchemaVersion = "0.4.13"
val ZioSchemaVersion = "0.4.14"
val SttpVersion = "3.3.18"

val `jwt-core` = "com.github.jwt-scala" %% "jwt-core" % JwtCoreVersion
Expand Down
7 changes: 4 additions & 3 deletions project/Shading.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ object Shading {
} else Nil

lazy val shadingEnabled = {
val enabled = sys.props.get(sysprops.`publish.shaded`).fold(false)(_.toBoolean) ||
val enabled = sys.props.get(sysprops.`publish.shaded`).fold(false)(_.toBoolean) ||
sys.env.get(env.PUBLISH_SHADED).fold(false)(_.toBoolean)
println(s"*** shading enabled: $enabled (env.PUBLISH_SHADED=${sys.env.get(env.PUBLISH_SHADED)}, sysprops.`publish.shaded`=${sys.props.get(sysprops.`publish.shaded`)})")
println(s"*** shading enabled: $enabled (env.PUBLISH_SHADED=${sys.env
.get(env.PUBLISH_SHADED)}, sysprops.`publish.shaded`=${sys.props.get(sysprops.`publish.shaded`)})")
enabled
}

def plugins(): Seq[Plugins] = if(shadingEnabled) Seq(ShadingPlugin) else Nil
def plugins(): Seq[Plugins] = if (shadingEnabled) Seq(ShadingPlugin) else Nil
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.0
sbt.version=1.9.6
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.4")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.6")
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.3")
addSbtPlugin("io.spray" % "sbt-revolver" % "0.10.0")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.15.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.5.1")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.16.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scala3-migrate" % "0.6.1")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("dev.zio" % "zio-sbt-website" % "0.3.10")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8")
addSbtPlugin("io.get-coursier" % "sbt-shading" % "2.1.1")
addSbtPlugin("io.get-coursier" % "sbt-shading" % "2.1.3")
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ object EndpointGen {
List(transformOrFail, withDoc, withExamples).map(_.asInstanceOf[Mapper[CliReprOf[Codec[_]], Any]])

def transformOrFail[A] = Mapper[CliReprOf[Codec[A]], Any](
(repr, _: Any) => CliRepr(repr.value.transform((x: A) => x, (x: A) => x), repr.repr),
(repr, _: Any) => CliRepr(repr.value.transform((x: A) => x)((x: A) => x), repr.repr),
Gen.empty,
)

Expand Down
12 changes: 12 additions & 0 deletions zio-http-testkit/src/main/scala/zio/http/TestChannel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ case class TestChannel(
promise.await
def receive(implicit trace: Trace): Task[WebSocketChannelEvent] =
in.take
def receiveAll[Env, Err](f: WebSocketChannelEvent => ZIO[Env, Err, Any])(implicit
trace: Trace,
): ZIO[Env, Err, Unit] = {
lazy val loop: ZIO[Env, Err, Unit] =
in.take.flatMap {
case event @ ChannelEvent.ExceptionCaught(_) => f(event).unit
case event @ ChannelEvent.Unregistered => f(event).unit
case event => f(event) *> ZIO.yieldNow *> loop
}

loop
}
def send(in: WebSocketChannelEvent)(implicit trace: Trace): Task[Unit] =
out.offer(in).unit
def sendAll(in: Iterable[WebSocketChannelEvent])(implicit trace: Trace): Task[Unit] =
Expand Down
37 changes: 20 additions & 17 deletions zio-http/src/main/scala/zio/http/Channel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ trait Channel[-In, +Out] { self =>
*/
def receive(implicit trace: Trace): Task[Out]

/**
* Reads all messages from the channel, handling them with the specified
* function.
*/
def receiveAll[Env, Err](f: Out => ZIO[Env, Err, Any])(implicit trace: Trace): ZIO[Env, Err, Unit]

/**
* Send a message to the channel.
*/
Expand All @@ -57,15 +63,17 @@ trait Channel[-In, +Out] { self =>
*/
final def contramap[In2](f: In2 => In): Channel[In2, Out] =
new Channel[In2, Out] {
def awaitShutdown(implicit trace: Trace): UIO[Unit] =
def awaitShutdown(implicit trace: Trace): UIO[Unit] =
self.awaitShutdown
def receive(implicit trace: Trace): Task[Out] =
def receive(implicit trace: Trace): Task[Out] =
self.receive
def send(in: In2)(implicit trace: Trace): Task[Unit] =
def receiveAll[Env, Err](g: Out => ZIO[Env, Err, Any])(implicit trace: Trace): ZIO[Env, Err, Unit] =
self.receiveAll(g)
def send(in: In2)(implicit trace: Trace): Task[Unit] =
self.send(f(in))
def sendAll(in: Iterable[In2])(implicit trace: Trace): Task[Unit] =
def sendAll(in: Iterable[In2])(implicit trace: Trace): Task[Unit] =
self.sendAll(in.map(f))
def shutdown(implicit trace: Trace): UIO[Unit] =
def shutdown(implicit trace: Trace): UIO[Unit] =
self.shutdown
}

Expand All @@ -75,22 +83,17 @@ trait Channel[-In, +Out] { self =>
*/
final def map[Out2](f: Out => Out2)(implicit trace: Trace): Channel[In, Out2] =
new Channel[In, Out2] {
def awaitShutdown(implicit trace: Trace): UIO[Unit] =
def awaitShutdown(implicit trace: Trace): UIO[Unit] =
self.awaitShutdown
def receive(implicit trace: Trace): Task[Out2] =
def receive(implicit trace: Trace): Task[Out2] =
self.receive.map(f)
def send(in: In)(implicit trace: Trace): Task[Unit] =
def receiveAll[Env, Err](g: Out2 => ZIO[Env, Err, Any])(implicit trace: Trace): ZIO[Env, Err, Unit] =
self.receiveAll(f andThen g)
def send(in: In)(implicit trace: Trace): Task[Unit] =
self.send(in)
def sendAll(in: Iterable[In])(implicit trace: Trace): Task[Unit] =
def sendAll(in: Iterable[In])(implicit trace: Trace): Task[Unit] =
self.sendAll(in)
def shutdown(implicit trace: Trace): UIO[Unit] =
def shutdown(implicit trace: Trace): UIO[Unit] =
self.shutdown
}

/**
* Reads all messages from the channel, handling them with the specified
* function.
*/
final def receiveAll[Env](f: Out => ZIO[Env, Throwable, Any])(implicit trace: Trace): ZIO[Env, Throwable, Nothing] =
receive.flatMap(f).forever
}
12 changes: 11 additions & 1 deletion zio-http/src/main/scala/zio/http/Handler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ sealed trait Handler[-R, +Err, -In, +Out] { self =>
* the handler has been appropriately sandboxed, turning all possible failures
* into well-formed HTTP responses.
*/
def toHttpApp(implicit err: Err <:< Response, in: Request <:< In, out: Out <:< Response): HttpApp[R] = {
def toHttpApp(implicit err: Err <:< Response, in: Request <:< In, out: Out <:< Response, trace: Trace): HttpApp[R] = {
val handler: Handler[R, Response, Request, Response] =
self.asInstanceOf[Handler[R, Response, Request, Response]]

Expand Down Expand Up @@ -660,6 +660,16 @@ sealed trait Handler[-R, +Err, -In, +Out] { self =>

object Handler {

def asChunkBounded(request: Request, limit: Int)(implicit trace: Trace): Handler[Any, Throwable, Any, Chunk[Byte]] =
Handler.fromZIO(
request.body.asStream.chunks
.runFoldZIO(Chunk.empty[Byte]) { case (acc, bytes) =>
ZIO
.succeed(acc ++ bytes)
.filterOrFail(_.size < limit)(new Exception("Too large input"))
},
)

/**
* Attempts to create a Handler that succeeds with the provided value,
* capturing all exceptions on it's way.
Expand Down
4 changes: 2 additions & 2 deletions zio-http/src/main/scala/zio/http/HandlerAspect.scala
Original file line number Diff line number Diff line change
Expand Up @@ -596,15 +596,15 @@ private[http] trait HandlerAspects extends zio.http.internal.HeaderModifier[Hand
/**
* Creates a middleware that will redirect requests to the specified URL.
*/
def redirect(url: URL, isPermanent: Boolean): HandlerAspect[Any, Unit] =
def redirect(url: URL, isPermanent: Boolean = false): HandlerAspect[Any, Unit] =
fail(Response.redirect(url, isPermanent))

/**
* Creates middleware that will redirect requests with trailing slash to the
* same path without trailing slash.
*/
def redirectTrailingSlash(
isPermanent: Boolean,
isPermanent: Boolean = false,
): HandlerAspect[Any, Unit] =
ifRequestThenElse(request => request.url.path.hasTrailingSlash && request.url.queryParams.isEmpty)(
ifTrue = updatePath(_.dropTrailingSlash) ++ failWith(request => Response.redirect(request.url, isPermanent)),
Expand Down
Loading

0 comments on commit 47a0fb4

Please sign in to comment.