Closed Frityet closed 8 months ago
calling Response.statusCode()
sets the status code for the response that's eventually sent. You're probably getting an error because you're calling res:write()
(which sends the response headers) right before res:statusCode()
I suspect it should be written with the statusCode()
call first, then the method that actually sends the response (similar to the spec)
Example:
res:statusCode(404, "Not Found")
res:write(doc)
calling
Response.statusCode()
sets the status code for the response that's eventually sent. You're probably getting an error because you're callingres:write()
(which sends the response headers) right beforeres:statusCode()
I suspect it should be written with the
statusCode()
call first, then the method that actually sends the response (similar to the spec)Example:
res:statusCode(404, "Not Found") res:write(doc)
Right, that makes sense, is reading the spec the only good way to learn about cases like this?
Right, that makes sense, is reading the spec the only good way to learn about cases like this?
I sometimes find it to be an effective way to figure out how to use something that isn't fully documented :) I'm sure the maintainers would be open to PRs or suggestions for docs on this though!
To be honest, I've never used this library 😅 (I mostly follow it out of interest and I appreciate its simplicity/readability) - I just found your issue interesting and tractable, and was able to follow the source code to understand what the implementation does.
Thanks, @achou11 for helping with this issue. Was about to jump into it, but I see you already supported @Frityet :)
I know our docs are not the best at this point, so feel free to open PRs to improve it guys
Closing the PR, but please re-open it if it's needed @Frityet
Thank you! Alongside adding annotations with #140 I will try and add documentation as well
I still do not know how to properly use this function.
Here is my code
I currently have errors when a request runs because it "was already sent", but I can find no docs on when things are actually sent, if possible documenting this would be nice