Comparison

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
comparison
equal deleted inserted replaced
13259:9097149923ae 13260:da21185fd026
105 self.data.conn:pause(); 105 self.data.conn:pause();
106 end 106 end
107 107
108 function runner_callbacks:error(err) 108 function runner_callbacks:error(err)
109 log("error", "Traceback[httpserver]: %s", err); 109 log("error", "Traceback[httpserver]: %s", err);
110 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 })); 110 local response = { headers = { content_type = "text/plain" }; body = "" };
111 response.body = events.fire_event("http-error", { code = 500; private_message = err; response = response });
112 self.data.conn:write("HTTP/1.0 500 Internal Server Error\r\n\z\
113 X-Content-Type-Options: nosniff\r\n\z\
114 Content-Type: " .. response.header.content_type .. "\r\n\r\n");
115 self.data.conn:write(response.body);
111 self.data.conn:close(); 116 self.data.conn:close();
112 end 117 end
113 118
114 local function noop() end 119 local function noop() end
115 function listener.onconnect(conn) 120 function listener.onconnect(conn)