-
-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Invalid or incomplete multibyte or wide character #225
Comments
This is your operating system's standard error message when a function returns lua-http/http/h1_connection.lua Line 172 in ddab283
lua-http generally doesn't return any error messages for such calls, only errno values (see https://en.wikipedia.org/wiki/Errno.h, |
sure, I suppose it does return an errno as expected. but then somewhere along the line after I return from onstream, it throws an error. onstream = function(server, stream)
local headers, err = stream:get_headers()
if headers then
stream:write_body_from_string("hello, world!")
else
print("oh no, an error occurred. allow me to handle it properly.")
print("I surely don't need to crash.")
end
end
|
Add an @@ -1,14 +1,17 @@
local http_server = require "http.server"
local server = assert(http_server.listen {
host = "127.0.0.1",
port = 8080,
onstream = function(server, stream)
local headers = stream:get_headers()
if headers then
stream:write_body_from_string("hello, world!")
end
end,
+ onerror = function(server, context, op, err, errno)
+ io.stderr:write(string.format("ERROR! [%s:%d]: %s\n", op, errno, err))
+ end,
})
assert(server:loop()) |
while I appreciate that this does technically solve the problem, I intentionally do not use this feature because I think it is an antipattern. there's a difference between illegal characters in an HTTP request and dividing by zero. it's like I was under the impression that I could handle error conditions in this library by checking the return values and that it would not raise errors in the case of e.g. invalid input. |
That's what the If you look at the examples you'll see that lua-http/examples/server_hello.lua Lines 46 to 51 in ddab283
|
ok, I see. so, how do I distinguish I/O errors from normal lua errors with the context argument? edit:
this is what I'd like to avoid doing. |
if you connect to a lua-http server and send it unix newlines (which I'm aware is invalid), it will throw with a somewhat cryptic error, rather than returning an error value or tolerating it.
reproduction:
The text was updated successfully, but these errors were encountered: