Skip to content

Commit 67d88d2

Browse files
committed
Add man page to list all http-codes.
man 7 http-codes
1 parent ce60259 commit 67d88d2

File tree

1 file changed

+51
-4
lines changed

1 file changed

+51
-4
lines changed

build-manpages

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,46 @@
44
require "yaml"
55
require "fileutils"
66

7-
TEMPLATE = <<-EOF
7+
CATEGORIES = {
8+
1 => "The request was received, continuing process.",
9+
2 => "The request was successfully received, understood, and accepted.",
10+
3 => "Further action needs to be taken in order to complete the request.",
11+
4 => "The request contains bad syntax or cannot be fulfilled.",
12+
5 => "The server failed to fulfil an apparently valid request."
13+
}
14+
15+
COPYRIGHT = <<-EOF
816
.\\" Copyright © CC BY-SA Mozilla Contributors <https://developer.mozilla.org/en-US/docs/Web/HTTP/Status>
917
.\\"
1018
.\\" Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply.
1119
.\\" Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.
1220
.\\"
21+
EOF
22+
23+
TEMPLATE = <<-EOF
1324
.TH %{code} 7 "" "" "HTTP Status Code Manual"
1425
.SH CODE
1526
%{code} \- %{message}
1627
.SH CATEGORY
1728
%{category}
1829
.SH DESCRIPTION
1930
%{description}
31+
.SH CONFORMING TO
32+
RFC 7231 - \\%%https://datatracker.ietf.org/doc/html/rfc7231.
33+
.SH SEE ALSO
34+
.BR http-codes (7)
35+
EOF
36+
37+
HTTP_CODES_HEADER = <<-EOF
38+
.TH http-codes 7 "" "" "HTTP Status Code Manual"
39+
.SH HTTP RESPONSE STATUS CODES
40+
HTTP response status codes indicate whether a specific HTTP request has been successfully completed.
41+
Responses are grouped in the five classes listed bellow.
42+
EOF
43+
44+
HTTP_CODES_FOOTER = <<-EOF
45+
.SH SEE ALSO
46+
RFC 7231 - \\%https://datatracker.ietf.org/doc/html/rfc7231.
2047
EOF
2148

2249
BUILD_DIR = "./build"
@@ -26,8 +53,28 @@ codes = YAML.safe_load(File.read("./data/code_descriptions.yml"))
2653
codes.each do |code, info|
2754
info = info.transform_keys!(&:to_sym)
2855
info[:code] = code
29-
File.open("#{BUILD_DIR}/#{code}.7", "w") do |f|
30-
f.printf(TEMPLATE, info)
56+
File.open("#{BUILD_DIR}/#{code}.7", "w") do |fp|
57+
fp.puts(COPYRIGHT)
58+
fp.printf(TEMPLATE, info)
59+
end
60+
end
61+
62+
File.open("#{BUILD_DIR}/http-codes.7", "w") do |fp|
63+
fp.puts(COPYRIGHT)
64+
fp.puts(HTTP_CODES_HEADER)
65+
last_category = nil
66+
codes.each do |code, info|
67+
category = info[:category]
68+
if category != last_category
69+
fp.puts(".SH #{category.upcase}")
70+
fp.puts(CATEGORIES[code/100])
71+
last_category = category
72+
end
73+
fp.puts ".TP\n" \
74+
".B #{code}\n" \
75+
"#{info[:message]}"
3176
end
77+
fp.puts(HTTP_CODES_FOOTER)
3278
end
33-
puts "#{codes.size} man pages created at #{BUILD_DIR}."
79+
80+
puts "#{codes.size + 1} man pages created at #{BUILD_DIR}."

0 commit comments

Comments
 (0)