From d62efd6aaa7a408e04484f26d97b3b74114cc4b6 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Wed, 13 May 2020 23:35:01 +0200 Subject: setup http status code registry --- http-status-codes/Makefile | 31 +++++++++++++ http-status-codes/README | 7 +++ http-status-codes/extend.sh | 19 ++++++++ http-status-codes/extras.rec | 13 ++++++ http-status-codes/h.footer | 13 ++++++ http-status-codes/h.header | 40 +++++++++++++++++ http-status-codes/h.template | 6 +++ http-status-codes/http-status-codes-1.csv | 74 +++++++++++++++++++++++++++++++ http-status-codes/types.rec | 19 ++++++++ 9 files changed, 222 insertions(+) create mode 100644 http-status-codes/Makefile create mode 100644 http-status-codes/README create mode 100755 http-status-codes/extend.sh create mode 100644 http-status-codes/extras.rec create mode 100644 http-status-codes/h.footer create mode 100644 http-status-codes/h.header create mode 100644 http-status-codes/h.template create mode 100644 http-status-codes/http-status-codes-1.csv create mode 100644 http-status-codes/types.rec diff --git a/http-status-codes/Makefile b/http-status-codes/Makefile new file mode 100644 index 0000000..cea962b --- /dev/null +++ b/http-status-codes/Makefile @@ -0,0 +1,31 @@ +FILES=registry.rec http-status-codes.h +all: check $(FILES) +check: registry.rec + recfix --check registry.rec + +# http-status-codes-1.csv is from IANA! +iana.tmp: http-status-codes-1.csv + cat $^ | grep -v Unassigned | csv2rec > $@ + +# extend by all-caps descriptions suitable for C-style identifier generation +iana-extended.tmp: iana.tmp + ./extend.sh $@ $^ + +registry.rec: types.rec iana-extended.tmp extras.rec + cat $^ > $@ + +distclean: + rm -f *.tmp + +clean: + rm -f $(FILES) *.tmp + + +http-status-codes.h.tmp: registry.rec h.template + ../format.sh h.template < registry.rec > $@ + +http-status-codes.h: h.header http-status-codes.h.tmp h.footer + cat $^ > $@ + + +.PHONY: check clean distclean diff --git a/http-status-codes/README b/http-status-codes/README new file mode 100644 index 0000000..cc1ec53 --- /dev/null +++ b/http-status-codes/README @@ -0,0 +1,7 @@ +HTTP status code registry. + +Based on CSV export of +https://www.iana.org/assignments/http-status-codes/http-status-codes.xhtml + +Extended with vendor-specific status codes (see extras.rec) and C-style +identifiers suitable for code generation based on the descriptions. diff --git a/http-status-codes/extend.sh b/http-status-codes/extend.sh new file mode 100755 index 0000000..679d541 --- /dev/null +++ b/http-status-codes/extend.sh @@ -0,0 +1,19 @@ +#!/bin/sh +# Extend all IANA records with a C-style identifier in all-caps. +set -eu + +TARGET="$1" +shift +cat "$@" > ${TARGET} + +for n in `seq 100 599` +do + VAL=`recsel -e "Value = $n" -P Description iana.rec || true` + CAPS=`echo ${VAL} | tr [a-z] [A-Z] | tr " -" "__"` + recset -f Identifier -a "${CAPS}" -e "Value = $n" ${TARGET} +done + + +# Apply fixes for records defined differently by MHD: +recset -f Identifier -s "SWITCH_PROXY" -e "Value = 306" ${TARGET} +recset -f Description -s "Switch proxy (not used)" -e "Value = 306" ${TARGET} diff --git a/http-status-codes/extras.rec b/http-status-codes/extras.rec new file mode 100644 index 0000000..6251e4a --- /dev/null +++ b/http-status-codes/extras.rec @@ -0,0 +1,13 @@ + + +# Record types defined outside of IANA (and supported by GNU libmicrohttpd) +# +Value: 449 +Description: Retry with +Reference: [MS IIS extension] +Identifier: RETRY_WITH + +Value: 509 +Description: Bandwidth Limit Exceeded +Reference: [Apache extension] +Identifier: BANDWIDTH_LIMIT_EXCEEDED diff --git a/http-status-codes/h.footer b/http-status-codes/h.footer new file mode 100644 index 0000000..5d32ee9 --- /dev/null +++ b/http-status-codes/h.footer @@ -0,0 +1,13 @@ + + +}; + + +#if 0 /* keep Emacsens' auto-indent happy */ +{ +#endif +#ifdef __cplusplus +} +#endif + +#endif diff --git a/http-status-codes/h.header b/http-status-codes/h.header new file mode 100644 index 0000000..aeb50a3 --- /dev/null +++ b/http-status-codes/h.header @@ -0,0 +1,40 @@ +/* + This file is part of GNU libmicrohttpd + Copyright (C) 2012-2020 GNUnet e.V. + + GNU libmicrohttpd is free software: you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNU libmicrohttpd is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . + + SPDX-License-Identifier: LGPL3.0-or-later + */ +#ifndef GNU_LIBMICROHTTPD_HTTP_STATUS_CODES_H +#define GNU_LIBMICROHTTPD_HTTP_STATUS_CODES_H + +#ifdef __cplusplus +extern "C" { +#if 0 /* keep Emacsens' auto-indent happy */ +} +#endif +#endif + + +/** + * HTTP status codes as per RFC 7231 plus vendor extensions. + * + * 1xx: Informational - Request received, continuing process + * 2xx: Success - The action was successfully received, understood, and accepted + * 3xx: Redirection - Further action must be taken in order to complete the request + * 4xx: Client Error - The request contains bad syntax or cannot be fulfilled + * 5xx: Server Error - The server failed to fulfill an apparently valid request + */ +enum MHD_HTTP_StatusCode { diff --git a/http-status-codes/h.template b/http-status-codes/h.template new file mode 100644 index 0000000..bb8d339 --- /dev/null +++ b/http-status-codes/h.template @@ -0,0 +1,6 @@ + + + /** + * {{Description}} {{Reference}} + */ + MHD_HTTP_{{Identifier}} = {{Value}}, diff --git a/http-status-codes/http-status-codes-1.csv b/http-status-codes/http-status-codes-1.csv new file mode 100644 index 0000000..9abdcae --- /dev/null +++ b/http-status-codes/http-status-codes-1.csv @@ -0,0 +1,74 @@ +Value,Description,Reference +100,Continue,"[RFC7231, Section 6.2.1]" +101,Switching Protocols,"[RFC7231, Section 6.2.2]" +102,Processing,[RFC2518] +103,Early Hints,[RFC8297] +104-199,Unassigned, +200,OK,"[RFC7231, Section 6.3.1]" +201,Created,"[RFC7231, Section 6.3.2]" +202,Accepted,"[RFC7231, Section 6.3.3]" +203,Non-Authoritative Information,"[RFC7231, Section 6.3.4]" +204,No Content,"[RFC7231, Section 6.3.5]" +205,Reset Content,"[RFC7231, Section 6.3.6]" +206,Partial Content,"[RFC7233, Section 4.1]" +207,Multi-Status,[RFC4918] +208,Already Reported,[RFC5842] +209-225,Unassigned, +226,IM Used,[RFC3229] +227-299,Unassigned, +300,Multiple Choices,"[RFC7231, Section 6.4.1]" +301,Moved Permanently,"[RFC7231, Section 6.4.2]" +302,Found,"[RFC7231, Section 6.4.3]" +303,See Other,"[RFC7231, Section 6.4.4]" +304,Not Modified,"[RFC7232, Section 4.1]" +305,Use Proxy,"[RFC7231, Section 6.4.5]" +306,(Unused),"[RFC7231, Section 6.4.6]" +307,Temporary Redirect,"[RFC7231, Section 6.4.7]" +308,Permanent Redirect,[RFC7538] +309-399,Unassigned, +400,Bad Request,"[RFC7231, Section 6.5.1]" +401,Unauthorized,"[RFC7235, Section 3.1]" +402,Payment Required,"[RFC7231, Section 6.5.2]" +403,Forbidden,"[RFC7231, Section 6.5.3]" +404,Not Found,"[RFC7231, Section 6.5.4]" +405,Method Not Allowed,"[RFC7231, Section 6.5.5]" +406,Not Acceptable,"[RFC7231, Section 6.5.6]" +407,Proxy Authentication Required,"[RFC7235, Section 3.2]" +408,Request Timeout,"[RFC7231, Section 6.5.7]" +409,Conflict,"[RFC7231, Section 6.5.8]" +410,Gone,"[RFC7231, Section 6.5.9]" +411,Length Required,"[RFC7231, Section 6.5.10]" +412,Precondition Failed,"[RFC7232, Section 4.2][RFC8144, Section 3.2]" +413,Payload Too Large,"[RFC7231, Section 6.5.11]" +414,URI Too Long,"[RFC7231, Section 6.5.12]" +415,Unsupported Media Type,"[RFC7231, Section 6.5.13][RFC7694, Section 3]" +416,Range Not Satisfiable,"[RFC7233, Section 4.4]" +417,Expectation Failed,"[RFC7231, Section 6.5.14]" +418-420,Unassigned, +421,Misdirected Request,"[RFC7540, Section 9.1.2]" +422,Unprocessable Entity,[RFC4918] +423,Locked,[RFC4918] +424,Failed Dependency,[RFC4918] +425,Too Early,[RFC8470] +426,Upgrade Required,"[RFC7231, Section 6.5.15]" +427,Unassigned, +428,Precondition Required,[RFC6585] +429,Too Many Requests,[RFC6585] +430,Unassigned, +431,Request Header Fields Too Large,[RFC6585] +432-450,Unassigned, +451,Unavailable For Legal Reasons,[RFC7725] +452-499,Unassigned, +500,Internal Server Error,"[RFC7231, Section 6.6.1]" +501,Not Implemented,"[RFC7231, Section 6.6.2]" +502,Bad Gateway,"[RFC7231, Section 6.6.3]" +503,Service Unavailable,"[RFC7231, Section 6.6.4]" +504,Gateway Timeout,"[RFC7231, Section 6.6.5]" +505,HTTP Version Not Supported,"[RFC7231, Section 6.6.6]" +506,Variant Also Negotiates,[RFC2295] +507,Insufficient Storage,[RFC4918] +508,Loop Detected,[RFC5842] +509,Unassigned, +510,Not Extended,[RFC2774] +511,Network Authentication Required,[RFC6585] +512-599,Unassigned, diff --git a/http-status-codes/types.rec b/http-status-codes/types.rec new file mode 100644 index 0000000..431a9b1 --- /dev/null +++ b/http-status-codes/types.rec @@ -0,0 +1,19 @@ +# -*- mode: rec -*- +# +# Registry for HTTP status codes +# +%rec: HttpStatusCode +%key: Value +%typedef: ValueRange_t range 100 599 +%type: Value ValueRange_t +%mandatory: Value +%typedef: Description_t regexp /^[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-][abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_\(\) -]*$/ +%type: Description Description_t +%unique: Description +%mandatory: Description +%typedef: Identifier_t regexp /^[ABCDEFGHIJKLMNOPQRSTUVWXYZ_][ABCDEFGHIJKLMNOPQRSTUVWXYZ_0123456789]*$/ +%type: Identifier Identifier_t +%unique: Identifier +%mandatory: Identifier +%allowed: Reference +%sort: Number -- cgit v1.2.3