Add BlockingHttp4sServlet #1830
Conversation
Thanks! This is going to be unpopular, but if we move most of this into an abstract class, and leave the Alternatively, we could pass an |
|
||
class BlockingHttp4sServlet[F[_]]( | ||
service: HttpRoutes[F], | ||
servletIo: BlockingServletIo[F], |
rossabaker
May 7, 2018
Member
What's the benefit of parameterizing this? To configure the chunk size? I like that it mandates BlockingServletIo
for this use case.
What's the benefit of parameterizing this? To configure the chunk size? I like that it mandates BlockingServletIo
for this use case.
Taig
May 8, 2018
Author
Contributor
I wanted to keep the chunkSize
configurable but also mimic the API of Http4sSevlet
for consistency
I wanted to keep the chunkSize
configurable but also mimic the API of Http4sSevlet
for consistency
) | ||
|
||
F.runAsync(render) { | ||
case Right(_) => Sync[IO].unit |
rossabaker
May 7, 2018
Member
IO.unit
IO.unit
|
||
F.runAsync(render) { | ||
case Right(_) => Sync[IO].unit | ||
case Left(t) => Sync[IO].delay(errorHandler(servletResponse)(t)) |
rossabaker
May 7, 2018
Member
IO(errorHandler(...))
IO(errorHandler(...))
.unsafeRunSync() | ||
} catch errorHandler(servletResponse) | ||
|
||
private def onParseFailure( |
rossabaker
May 7, 2018
Member
I think everything here below is a copy-paste and could move into an abstract class? Make them protected
.
I think everything here below is a copy-paste and could move into an abstract class? Make them protected
.
extends HttpServlet { | ||
private[this] val logger = getLogger | ||
|
||
private[this] var serverSoftware: ServerSoftware = _ |
rossabaker
May 7, 2018
Member
Could be protected and moved to abstract class.
Could be protected and moved to abstract class.
private[this] var serverSoftware: ServerSoftware = _ | ||
|
||
// micro-optimization: unwrap the service and call its .run directly | ||
private[this] val serviceFn = service.run |
rossabaker
May 7, 2018
Member
Could be protected and move to abstract class. Though maybe we save a few nanoseconds going through a field (e.g., private[this]
) instead of an accessor.
Could be protected and move to abstract class. Though maybe we save a few nanoseconds going through a field (e.g., private[this]
) instead of an accessor.
Any naming preferences for the abstract class? I would probably name it |
I think I can live with the breaking change on master, but that means we can't add it in the 0.18 series, and you probably want this now. If we call the base class The division looks good. |
I'm fine with keeping my own copy of this around until 0.19 is released, so that's not an issue for me. Let me know if you want the renaming, I don't mind waiting for 0.19. |
We could even backport the copy-and-pasted version to 0.18 if you need it now. I think it's better to move forward with the better names, so this looks good for master. |
If we're happy waiting, I'm happy with it. |
Test failure is related, fixed by #1836. |
The current
Http4sServlet
uses the asyncServlet
feature in its implementation. Unfortunately this is not supported in the Google App Engine (GAE) standard environment so that a blocking implementation is necessary.Consider this PR as an initial draft. I started off by copying the
Http4sServlet
and ripping it apart. So there is currently quite a lot of code duplication which should be improved.Please note that I have never worked with
Servlet
nor withcats.Effect
before, so unfortunately some of the changes here were a bit of guesswork for me.