Skip to content

Commit

Permalink
use default not found instead of not implemented; allow override
Browse files Browse the repository at this point in the history
  • Loading branch information
alterationx10 committed Dec 28, 2024
1 parent f33c951 commit 208dfcb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ trait ContextHandler(val path: String) {
RequestHandler[?, ?]
]

/** A default handler for requests that are not found. Override this to
* provide a custom 404 handler.
*/
val notFoundRequestHandler: RequestHandler[?, ?] =
RequestHandler.notFoundHandler

private[spider] inline def httpHandler: HttpHandler = {
(exchange: HttpExchange) =>
{
Expand All @@ -42,7 +48,7 @@ trait ContextHandler(val path: String) {
)
.filter(contextRouter.isDefinedAt)
.map(contextRouter)
.getOrElse(RequestHandler.unimplementedHandler)
.getOrElse(notFoundRequestHandler)
}
.flatMap(_.lzyRun(exchange))
.recover { e =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,10 @@ object RequestHandler {
throw new Exception("Not implemented")
}

private[spider] val notFoundHandler: RequestHandler[Unit, String] =
new RequestHandler[Unit, String] {
override def handle(request: Request[Unit]): Response[String] =
Response(404, "Not found")
}

}

0 comments on commit 208dfcb

Please sign in to comment.