Software /
code /
prosody
Diff
net/http/server.lua @ 13260:da21185fd026
net.http.server: Support setting Content-Type of uncaught HTTP errors
mod_http_errors normally sets the Content-Type header via the response
object, which isn't available when handling these uncaught errors.
Without a Content-Type header the browser is forced to guess, which may
or may not result in something sensible.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 22 Sep 2023 01:47:21 +0200 |
parent | 13118:6b5e92949051 |
child | 13261:7c62370dee9a |
line wrap: on
line diff
--- a/net/http/server.lua Sat Sep 16 14:23:08 2023 +0200 +++ b/net/http/server.lua Fri Sep 22 01:47:21 2023 +0200 @@ -107,7 +107,12 @@ function runner_callbacks:error(err) log("error", "Traceback[httpserver]: %s", err); - self.data.conn:write("HTTP/1.0 500 Internal Server Error\r\n\r\n"..events.fire_event("http-error", { code = 500, private_message = err })); + local response = { headers = { content_type = "text/plain" }; body = "" }; + response.body = events.fire_event("http-error", { code = 500; private_message = err; response = response }); + self.data.conn:write("HTTP/1.0 500 Internal Server Error\r\n\z\ + X-Content-Type-Options: nosniff\r\n\z\ + Content-Type: " .. response.header.content_type .. "\r\n\r\n"); + self.data.conn:write(response.body); self.data.conn:close(); end