Annotate

tools/http-status-codes.lua @ 13765:7c57fb2ffbb0 13.0

mod_websocket: Merge session close handling changes from mod_c2s (bug fixes) This should bring some fixes and general robustness that mod_websocket had missed out on. The duplicated code here is not at all ideal. To prevent this happening again, we should figure out how to have the common logic in a single place, while still being able to do the websocket-specific parts that we need. The main known bug that this fixes is that it's possible for a session to get into a non-destroyable state. For example, if we try to session:close() a hibernating session, then session.conn is nil and the function will simply return without doing anything. In the mod_c2s code we already handle this, and just destroy the session. But if a hibernating websocket session is never resumed or becomes non-resumable, it will become immortal! By merging the fix from mod_c2s, the session should now be correctly destroyed.
author Matthew Wild <mwild1@gmail.com>
date Tue, 11 Mar 2025 18:44:40 +0000
parent 13142:879a6a33c21b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9166
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- Generate net/http/codes.lua from IANA HTTP status code registry
13142
879a6a33c21b tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents: 12271
diff changeset
2 if not pcall(require, "prosody.loader") then
879a6a33c21b tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents: 12271
diff changeset
3 pcall(require, "loader");
879a6a33c21b tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents: 12271
diff changeset
4 end
9166
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
13142
879a6a33c21b tools: Update imports to use new prosody.* namespace
Kim Alvefur <zash@zash.se>
parents: 12271
diff changeset
6 local xml = require "prosody.util.xml";
12271
f31bb79f51d7 tools: Allow processing instructions in some XML parsing tools
Kim Alvefur <zash@zash.se>
parents: 9166
diff changeset
7 local registry = xml.parse(io.read("*a"), { allow_processing_instructions = true });
9166
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 io.write([[
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local response_codes = {
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 -- Source: http://www.iana.org/assignments/http-status-codes
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 ]]);
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 for record in registry:get_child("registry"):childtags("record") do
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 -- Extract values
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local value = record:get_child_text("value");
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local description = record:get_child_text("description");
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local ref = record:get_child_text("xref");
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 local code = tonumber(value);
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 -- Space between major groups
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 if code and code % 100 == 0 then
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 io.write("\n");
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 end
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 -- Reserved and Unassigned entries should be not be included
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 if description == "Reserved" or description == "Unassigned" or description == "(Unused)" then
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 code = nil;
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 -- Non-empty references become comments
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 if ref and ref:find("%S") then
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 ref = " -- " .. ref;
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 else
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 ref = "";
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 end
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 io.write((code and "\t[%d] = %q;%s\n" or "\t-- [%s] = %q;%s\n"):format(code or value, description, ref));
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 io.write([[};
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 for k,v in pairs(response_codes) do response_codes[k] = k.." "..v; end
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 return setmetatable(response_codes, { __index = function(_, k) return k.." Unassigned"; end })
cce55767004a tools: Add a tool to generate net.http.codes from IANA registry
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 ]]);