Skip to content

Commit

Permalink
Merge pull request #151 from http4s/merge-0.24-20230104
Browse files Browse the repository at this point in the history
Merge 0.24 -> 0.25
  • Loading branch information
rossabaker authored Jan 5, 2023
2 parents 38cc167 + 9c12d84 commit 0f2ce14
Show file tree
Hide file tree
Showing 14 changed files with 136 additions and 112 deletions.
48 changes: 19 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.12.16, 2.13.8, 3.2.1]
scala: [2.12.17, 2.13.10, 3.2.1]
java: [temurin@11, temurin@17]
project: [rootJVM]
exclude:
- scala: 2.12.16
- scala: 2.12.17
java: temurin@17
- scala: 3.2.1
java: temurin@17
Expand Down Expand Up @@ -89,30 +89,30 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Check that workflows are up to date
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' 'project /' githubWorkflowCheck
run: sbt githubWorkflowCheck

- name: Check headers and formatting
if: matrix.java == 'temurin@11'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck

- name: Test
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@11'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' mimaReportBinaryIssues
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
if: matrix.java == 'temurin@11'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' doc
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc

- name: Check scalafix lints
if: matrix.java == 'temurin@11' && !startsWith(matrix.scala, '3.')
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' 'scalafixAll --check'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' 'scalafixAll --check'

- name: Check unused compile dependencies
if: matrix.java == 'temurin@11'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' unusedCompileDependenciesTest
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' unusedCompileDependenciesTest

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand All @@ -136,7 +136,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8]
scala: [2.13.10]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -189,32 +189,22 @@ jobs:
~/Library/Caches/Coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.12.16, rootJVM)
- name: Download target directories (2.12.17, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.16-rootJVM
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootJVM

- name: Inflate target directories (2.12.16, rootJVM)
- name: Inflate target directories (2.12.17, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.8, rootJVM)
- name: Download target directories (2.13.10, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.8-rootJVM
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootJVM

- name: Inflate target directories (2.13.8, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.8, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.8-rootJVM

- name: Inflate target directories (2.13.8, rootJVM)
- name: Inflate target directories (2.13.10, rootJVM)
run: |
tar xf targets.tar
rm targets.tar
Expand All @@ -241,14 +231,14 @@ jobs:
(echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1)
- name: Publish
run: sbt '++${{ matrix.scala }}' tlRelease
run: sbt '++ ${{ matrix.scala }}' tlRelease

site:
name: Generate Site
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.8]
scala: [2.13.10]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -302,7 +292,7 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Generate site
run: sbt '++${{ matrix.scala }}' docs/tlSite
run: sbt '++ ${{ matrix.scala }}' docs/tlSite

- name: Publish site
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
Expand Down
9 changes: 7 additions & 2 deletions .scala-steward.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ updates.pin = [
]

updates.ignore = [
# Inherit from series/0.23
{ groupId = "org.http4s", artifactId = "sbt-http4s-org" }
# Inherit from series/0.24
{ groupId = "org.http4s", artifactId = "http4s-dsl" },
{ groupId = "org.http4s", artifactId = "http4s-server" },
{ groupId = "org.http4s", artifactId = "http4s-scalafix-internal" },
{ groupId = "org.http4s", artifactId = "sbt-http4s-org" },
{ groupId = "org.scala-lang", artifactId = "scala3-library" },
{ groupId = "org.scala-sbt", artifactId = "sbt" }
]
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.5.8
version = 3.6.1

style = default

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Runs http4s apps as Java servlets. Provides components for the [http4s-jetty][h

```scala
libraryDependencies ++= Seq(
"org.http4s" %% "http4s-servlet" % http4sScalatagsV
"org.http4s" %% "http4s-servlet" % http4sServletV
)
```

Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ ThisBuild / developers := List(
// publish website from this branch
ThisBuild / tlSitePublishBranch := Some("main")

val Scala213 = "2.13.8"
ThisBuild / crossScalaVersions := Seq("2.12.16", Scala213, "3.2.1")
val Scala213 = "2.13.10"
ThisBuild / crossScalaVersions := Seq("2.12.17", Scala213, "3.2.1")
ThisBuild / scalaVersion := Scala213 // the default Scala

// Jetty 10+, for testing, requires Java 11.
Expand All @@ -22,7 +22,7 @@ lazy val root = tlCrossRootProject.aggregate(servlet, examples)

val asyncHttpClientVersion = "2.12.3"
val jettyVersion = "11.0.13"
val http4sVersion = "0.23.12"
val http4sVersion = "0.23.17"
val munitCatsEffectVersion = "1.0.7"
val servletApiVersion = "5.0.0"

Expand Down
4 changes: 3 additions & 1 deletion examples/src/main/scala/com/example/Bootstrap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ class Bootstrap extends ServletContextListener {
@volatile private var shutdown: IO[Unit] = IO.unit

override def contextInitialized(sce: ServletContextEvent): Unit = {
Dispatcher[IO].allocated
Dispatcher
.parallel[IO]
.allocated
.flatMap { case (dispatcher, shutdown) =>
IO(this.shutdown = shutdown) *>
IO(sce.getServletContext.mountRoutes("example", routes, dispatcher = dispatcher))
Expand Down
41 changes: 12 additions & 29 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.6.2
sbt.version=1.8.1
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
addSbtPlugin("com.earldouglas" % "xsbt-web-plugin" % "4.2.4")
addSbtPlugin("org.http4s" % "sbt-http4s-org" % "0.14.3")
addSbtPlugin("org.http4s" % "sbt-http4s-org" % "0.14.9")
65 changes: 55 additions & 10 deletions servlet/src/main/scala/org/http4s/servlet/AsyncHttp4sServlet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ import jakarta.servlet.http.HttpServletRequest
import jakarta.servlet.http.HttpServletResponse
import org.http4s.server._

import scala.annotation.nowarn
import scala.concurrent.duration.Duration

class AsyncHttp4sServlet[F[_]](
service: HttpApp[F],
class AsyncHttp4sServlet[F[_]] @deprecated("Use AsyncHttp4sServlet.builder", "0.23.17") (
httpApp: HttpApp[F],
asyncTimeout: Duration = Duration.Inf,
servletIo: ServletIo[F],
serviceErrorHandler: ServiceErrorHandler[F],
dispatcher: Dispatcher[F],
)(implicit F: Async[F])
extends Http4sServlet[F](service, servletIo, dispatcher) {
extends Http4sServlet[F](httpApp, servletIo, dispatcher) {
private val asyncTimeoutMillis =
if (asyncTimeout.isFinite) asyncTimeout.toMillis else -1 // -1 == Inf

Expand Down Expand Up @@ -131,16 +132,60 @@ class AsyncHttp4sServlet[F[_]](
}

object AsyncHttp4sServlet {

class Builder[F[_]] private[AsyncHttp4sServlet] (
httpApp: HttpApp[F],
dispatcher: Dispatcher[F],
asyncTimeout: Option[Duration],
chunkSize: Option[Int],
) {
private def copy(
httpApp: HttpApp[F] = httpApp,
dispatcher: Dispatcher[F] = dispatcher,
asyncTimeout: Option[Duration] = asyncTimeout,
chunkSize: Option[Int] = chunkSize,
): Builder[F] =
new Builder[F](
httpApp,
dispatcher,
asyncTimeout,
chunkSize,
) {}

@nowarn("cat=deprecation")
def build(implicit F: Async[F]): AsyncHttp4sServlet[F] =
new AsyncHttp4sServlet(
httpApp,
asyncTimeout.getOrElse(Duration.Inf),
NonBlockingServletIo(chunkSize.getOrElse(DefaultChunkSize)),
DefaultServiceErrorHandler,
dispatcher,
)

def withHttpApp(httpApp: HttpApp[F]): Builder[F] =
copy(httpApp = httpApp)

def withDispatcher(dispatcher: Dispatcher[F]): Builder[F] =
copy(dispatcher = dispatcher)

def withAsyncTimeout(asyncTimeout: Duration): Builder[F] =
copy(asyncTimeout = Some(asyncTimeout))

def withChunkSize(chunkSize: Int): Builder[F] =
copy(chunkSize = Some(chunkSize))
}

def builder[F[_]](httpApp: HttpApp[F], dispatcher: Dispatcher[F]): Builder[F] =
new Builder[F](httpApp, dispatcher, None, None) {}

@deprecated("Use `builder`. `service` is renamed to `httpApp`.", "0.22.13")
def apply[F[_]: Async](
service: HttpApp[F],
asyncTimeout: Duration = Duration.Inf,
dispatcher: Dispatcher[F],
): AsyncHttp4sServlet[F] =
new AsyncHttp4sServlet[F](
service,
asyncTimeout,
NonBlockingServletIo[F](DefaultChunkSize),
DefaultServiceErrorHandler,
dispatcher,
)
AsyncHttp4sServlet
.builder[F](service, dispatcher)
.withAsyncTimeout(asyncTimeout)
.build
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import cats.effect._
import cats.effect.std.Dispatcher
import jakarta.servlet.ServletContext
import jakarta.servlet.ServletRegistration
import org.http4s.server.DefaultServiceErrorHandler
import org.http4s.server.defaults
import org.http4s.syntax.all._

Expand Down Expand Up @@ -51,13 +50,10 @@ final class ServletContextOps private[syntax] (val self: ServletContext) extends
dispatcher: Dispatcher[F],
asyncTimeout: Duration = defaults.ResponseTimeout,
): ServletRegistration.Dynamic = {
val servlet = new AsyncHttp4sServlet(
service = service,
asyncTimeout = asyncTimeout,
servletIo = NonBlockingServletIo(DefaultChunkSize),
serviceErrorHandler = DefaultServiceErrorHandler[F],
dispatcher,
)
val servlet = AsyncHttp4sServlet
.builder[F](service, dispatcher)
.withAsyncTimeout(asyncTimeout)
.build
val reg = self.addServlet(name, servlet)
reg.setLoadOnStartup(1)
reg.setAsyncSupported(true)
Expand Down
Loading

0 comments on commit 0f2ce14

Please sign in to comment.