util.x509: Nameprep commonName once
[prosody.git] / tools / http-status-codes.lua
blob39bee74cc088721abcd6e52bca9cf49f69de5313
1 -- Generate net/http/codes.lua from IANA HTTP status code registry
3 local xml = require "util.xml";
4 local registry = xml.parse(io.read("*a"));
6 io.write([[
8 local response_codes = {
9 -- Source: http://www.iana.org/assignments/http-status-codes
10 ]]);
12 for record in registry:get_child("registry"):childtags("record") do
13 -- Extract values
14 local value = record:get_child_text("value");
15 local description = record:get_child_text("description");
16 local ref = record:get_child_text("xref");
17 local code = tonumber(value);
19 -- Space between major groups
20 if code and code % 100 == 0 then
21 io.write("\n");
22 end
24 -- Reserved and Unassigned entries should be not be included
25 if description == "Reserved" or description == "Unassigned" or description == "(Unused)" then
26 code = nil;
27 end
29 -- Non-empty references become comments
30 if ref and ref:find("%S") then
31 ref = " -- " .. ref;
32 else
33 ref = "";
34 end
36 io.write((code and "\t[%d] = %q;%s\n" or "\t-- [%s] = %q;%s\n"):format(code or value, description, ref));
37 end
39 io.write([[};
41 for k,v in pairs(response_codes) do response_codes[k] = k.." "..v; end
42 return setmetatable(response_codes, { __index = function(_, k) return k.." Unassigned"; end })
43 ]]);