Skip to content

Commit

Permalink
Merge pull request #24 from http4s/weaken-constraints
Browse files Browse the repository at this point in the history
Weaken constraints
  • Loading branch information
rossabaker authored May 26, 2022
2 parents 70b4c5f + 2472613 commit f327cff
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand All @@ -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,
Expand Down Expand Up @@ -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],
Expand All @@ -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])
}
12 changes: 11 additions & 1 deletion servlet/src/main/scala/org/http4s/servlet/Http4sServlet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions servlet/src/main/scala/org/http4s/servlet/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f327cff

Please sign in to comment.