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"));
8 local response_codes = {
9 -- Source: http://www.iana.org/assignments/http-status-codes
12 for record
in registry
:get_child("registry"):childtags("record") do
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
24 -- Reserved and Unassigned entries should be not be included
25 if description
== "Reserved" or description
== "Unassigned" or description
== "(Unused)" then
29 -- Non-empty references become comments
30 if ref
and ref
:find("%S") then
36 io
.write((code
and "\t[%d] = %q;%s\n" or "\t-- [%s] = %q;%s\n"):format(code
or value
, description
, ref
));
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 })