diff --git a/lightbug_http/middleware/basicauth.mojo b/lightbug_http/middleware/basicauth.mojo index 8617c598..287046eb 100644 --- a/lightbug_http/middleware/basicauth.mojo +++ b/lightbug_http/middleware/basicauth.mojo @@ -10,7 +10,7 @@ struct BasicAuthMiddleware(Middleware): fn set_next(self, next: Middleware): self.next = next - fn __init__(self, username: String, password: String): + fn __init__(inout self, username: String, password: String): self.username = username self.password = password diff --git a/lightbug_http/middleware/cors.mojo b/lightbug_http/middleware/cors.mojo index cc4d60b9..67021e79 100644 --- a/lightbug_http/middleware/cors.mojo +++ b/lightbug_http/middleware/cors.mojo @@ -9,7 +9,7 @@ struct CorsMiddleware(Middleware): fn set_next(self, next: Middleware): self.next = next - fn __init__(self, allow_origin: String): + fn __init__(inout self, allow_origin: String): self.allow_origin = allow_origin fn call(self, context: Context) -> HTTPResponse: diff --git a/lightbug_http/middleware/notfound.mojo b/lightbug_http/middleware/notfound.mojo index 43719c48..1f6bf9b4 100644 --- a/lightbug_http/middleware/notfound.mojo +++ b/lightbug_http/middleware/notfound.mojo @@ -3,5 +3,10 @@ from lightbug_http.middleware.helpers import NotFound ## NotFound middleware returns a 404 response if no other middleware handles the request. It is a leaf node and always add at the end of the middleware chain @value struct NotFoundMiddleware(Middleware): + var next: Middleware + + fn set_next(self, next: Middleware): + self.next = next + fn call(self, context: Context) -> HTTPResponse: return NotFound("Not Found") diff --git a/lightbug_http/middleware/router.mojo b/lightbug_http/middleware/router.mojo index 8307c7b8..5aa7566c 100644 --- a/lightbug_http/middleware/router.mojo +++ b/lightbug_http/middleware/router.mojo @@ -17,7 +17,7 @@ struct RouterMiddleware[HTTPHandlerType: HTTPHandler](Middleware): fn set_next(self, next: Middleware): self.next = next - fn add(self, method: String, route: String, handler: HTTPHandler): + fn add(self, method: String, route: String, handler: HTTPHandlerType): self.routes[method + ":" + route] = handler fn call(self, context: Context) -> HTTPResponse: diff --git a/lightbug_http/middleware/static.mojo b/lightbug_http/middleware/static.mojo index 3634e388..d738e579 100644 --- a/lightbug_http/middleware/static.mojo +++ b/lightbug_http/middleware/static.mojo @@ -9,7 +9,7 @@ struct StaticMiddleware(Middleware): fn set_next(self, next: Middleware): self.next = next - fn __init__(self, path: String): + fn __init__(inout self, path: String): self.path = path fn call(self, context: Context) -> HTTPResponse: @@ -19,7 +19,7 @@ struct StaticMiddleware(Middleware): try: var html: String - with open(file, "r") as f: + with open(path, "r") as f: html = f.read() return Success(html, "text/html")