diff --git a/servlet/src/main/scala/org/http4s/servlet/AsyncHttp4sServlet.scala b/servlet/src/main/scala/org/http4s/servlet/AsyncHttp4sServlet.scala index a7a3f8b8..13ef0c11 100644 --- a/servlet/src/main/scala/org/http4s/servlet/AsyncHttp4sServlet.scala +++ b/servlet/src/main/scala/org/http4s/servlet/AsyncHttp4sServlet.scala @@ -108,7 +108,7 @@ class AsyncHttp4sServlet[F[_]]( val response = Response[F](Status.InternalServerError) // We don't know what I/O mode we're in here, and we're not rendering a body // anyway, so we use a NullBodyWriter. - val f = renderResponse(response, servletResponse, NullBodyWriter) *> + val f = renderResponse(response, servletResponse, nullBodyWriter) *> F.delay( if (servletRequest.isAsyncStarted) servletRequest.getAsyncContext.complete() diff --git a/servlet/src/main/scala/org/http4s/servlet/BlockingHttp4sServlet.scala b/servlet/src/main/scala/org/http4s/servlet/BlockingHttp4sServlet.scala index 24c5d5f6..04cd52c4 100644 --- a/servlet/src/main/scala/org/http4s/servlet/BlockingHttp4sServlet.scala +++ b/servlet/src/main/scala/org/http4s/servlet/BlockingHttp4sServlet.scala @@ -18,6 +18,7 @@ package org.http4s package servlet import cats.effect.kernel.Async +import cats.effect.kernel.Sync import cats.effect.std.Dispatcher import cats.syntax.all._ import org.http4s.server._ @@ -30,8 +31,19 @@ class BlockingHttp4sServlet[F[_]]( servletIo: ServletIo[F], serviceErrorHandler: ServiceErrorHandler[F], dispatcher: Dispatcher[F], -)(implicit F: Async[F]) +)(implicit F: Sync[F]) extends Http4sServlet[F](service, servletIo, dispatcher) { + + @deprecated("Binary compatibility", "0.23.12") + private[servlet] def this( + service: HttpApp[F], + servletIo: ServletIo[F], + serviceErrorHandler: ServiceErrorHandler[F], + dispatcher: Dispatcher[F], + async: Async[F], + ) = + this(service, servletIo, serviceErrorHandler, dispatcher)(async: Sync[F]) + override def service( servletRequest: HttpServletRequest, servletResponse: HttpServletResponse, @@ -71,13 +83,13 @@ class BlockingHttp4sServlet[F[_]]( val response = Response[F](Status.InternalServerError) // We don't know what I/O mode we're in here, and we're not rendering a body // anyway, so we use a NullBodyWriter. - renderResponse(response, servletResponse, NullBodyWriter) + renderResponse(response, servletResponse, nullBodyWriter) } } } object BlockingHttp4sServlet { - def apply[F[_]: Async]( + def apply[F[_]: Sync]( service: HttpApp[F], servletIo: ServletIo[F], dispatcher: Dispatcher[F], @@ -88,4 +100,16 @@ object BlockingHttp4sServlet { DefaultServiceErrorHandler, dispatcher, ) + + @deprecated( + "Preserved for binary compatibility. Use the overload with the implicit Sync", + "0.23.12", + ) + def apply[F[_]]( + service: HttpApp[F], + servletIo: ServletIo[F], + dispatcher: Dispatcher[F], + async: Async[F], + ): BlockingHttp4sServlet[F] = + apply(service, servletIo, dispatcher)(async: Sync[F]) } diff --git a/servlet/src/main/scala/org/http4s/servlet/Http4sServlet.scala b/servlet/src/main/scala/org/http4s/servlet/Http4sServlet.scala index f67a425d..c6893266 100644 --- a/servlet/src/main/scala/org/http4s/servlet/Http4sServlet.scala +++ b/servlet/src/main/scala/org/http4s/servlet/Http4sServlet.scala @@ -17,6 +17,7 @@ package org.http4s.servlet import cats.effect.kernel.Async +import cats.effect.kernel.Sync import cats.effect.std.Dispatcher import cats.syntax.all._ import com.comcast.ip4s.IpAddress @@ -42,8 +43,17 @@ abstract class Http4sServlet[F[_]]( service: HttpApp[F], servletIo: ServletIo[F], dispatcher: Dispatcher[F], -)(implicit F: Async[F]) +)(implicit F: Sync[F]) extends HttpServlet { + + @deprecated("Binary compatibility", "0.23.12") + private[servlet] def this( + service: HttpApp[F], + servletIo: ServletIo[F], + dispatcher: Dispatcher[F], + async: Async[F], + ) = this(service, servletIo, dispatcher)(async: Sync[F]) + protected val logger: Logger = getLogger // micro-optimization: unwrap the service and call its .run directly diff --git a/servlet/src/main/scala/org/http4s/servlet/package.scala b/servlet/src/main/scala/org/http4s/servlet/package.scala index c35609f1..47fc486d 100644 --- a/servlet/src/main/scala/org/http4s/servlet/package.scala +++ b/servlet/src/main/scala/org/http4s/servlet/package.scala @@ -16,12 +16,17 @@ package org.http4s +import cats.Applicative import cats.effect.Async package object servlet { protected[servlet] type BodyWriter[F[_]] = Response[F] => F[Unit] + @deprecated("Use nullBodyWriter with Applicative constraint", "0.23.12") protected[servlet] def NullBodyWriter[F[_]](implicit F: Async[F]): BodyWriter[F] = + nullBodyWriter[F] + + private[servlet] def nullBodyWriter[F[_]](implicit F: Applicative[F]): BodyWriter[F] = _ => F.unit protected[servlet] val DefaultChunkSize = 4096