Custom 404 code in handler causes failure at handler.lua:146
midn1 opened this issue · 3 comments
As in title, doing response:statusCode(404)
within a handler for a custom 404 response causes the response:writeDefaultErrorMessage
call at handler.lua:146 to crash the program.
Specifically, it tries to do a write when the response was already written.
This doesn't seem like a very niche requirement to me
Yes, I have seen that as well. The problem is with the Handler
implementation which mixes a set of different roles. To fix this however would be a breaking change.
My 2cts; the router I added in #131 should not actually be a plugin, but it should replace the Handler
. It should become the entry point for any request, and it should be possible to add plugins on a per-path basis. For example;
/static
-> File handler plugin, Compress plugin/downloads
-> Download plugin, Compress plugin/api
-> call-back based
etc.
But that would require breaking changes. Though would make for a great 1.0 version.
wdyt @EvandroLG ?
Though I'd prefer the ability to handle requests completely on my own, I wouldn't mind a fixed-function routing system either.
If you're going for the latter, route redirections will be a must (so I'd be able to, again, redirect to a 404 page)
that router does prefix matching, so a single path "/"
would allow you to handle everything.
Not entirely sure what you mean with;
route redirections will be a must (so I'd be able to, again, redirect to a 404 page)
care to elaborate?