diff --git a/branch/src/main/scala/dev/wishingtree/branch/spider/server/ContextHandler.scala b/branch/src/main/scala/dev/wishingtree/branch/spider/server/ContextHandler.scala index 28724f8..ecbc79c 100644 --- a/branch/src/main/scala/dev/wishingtree/branch/spider/server/ContextHandler.scala +++ b/branch/src/main/scala/dev/wishingtree/branch/spider/server/ContextHandler.scala @@ -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) => { @@ -42,7 +48,7 @@ trait ContextHandler(val path: String) { ) .filter(contextRouter.isDefinedAt) .map(contextRouter) - .getOrElse(RequestHandler.unimplementedHandler) + .getOrElse(notFoundRequestHandler) } .flatMap(_.lzyRun(exchange)) .recover { e => diff --git a/branch/src/main/scala/dev/wishingtree/branch/spider/server/RequestHandler.scala b/branch/src/main/scala/dev/wishingtree/branch/spider/server/RequestHandler.scala index a42440c..fbe895c 100644 --- a/branch/src/main/scala/dev/wishingtree/branch/spider/server/RequestHandler.scala +++ b/branch/src/main/scala/dev/wishingtree/branch/spider/server/RequestHandler.scala @@ -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") + } + }