From 0bac4cdf1a1aa27b62c5dc2717dfd64f4c0c8d92 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Wed, 27 May 2020 10:11:59 +0200 Subject: [PATCH] CLEANUP: http: Remove unused HTTP message templates HTTP_1XX, HTTP_3XX and HTTP_4XX message templates are no longer used. Only HTTP_302 and HTTP_303 are used during configuration parsing by "errorloc" family directives. So these templates are removed from the generic http code. And HTTP_302 and HTTP_303 templates are moved as static strings in the function parsing "errorloc" directives. --- include/common/http.h | 10 -------- src/http.c | 57 ------------------------------------------- src/http_htx.c | 11 +++++++++ 3 files changed, 11 insertions(+), 67 deletions(-) diff --git a/include/common/http.h b/include/common/http.h index d31f5e915..acf19903f 100644 --- a/include/common/http.h +++ b/include/common/http.h @@ -127,16 +127,6 @@ extern const char *http_err_msgs[HTTP_ERR_SIZE]; extern const struct ist http_known_methods[HTTP_METH_OTHER]; extern const uint8_t http_char_classes[256]; -extern const struct ist HTTP_100; -extern const struct ist HTTP_103; -extern const char *HTTP_301; -extern const char *HTTP_302; -extern const char *HTTP_303; -extern const char *HTTP_307; -extern const char *HTTP_308; -extern const char *HTTP_401_fmt; -extern const char *HTTP_407_fmt; - enum http_meth_t find_http_meth(const char *str, const int len); int http_get_status_idx(unsigned int status); const char *http_get_reason(unsigned int status); diff --git a/src/http.c b/src/http.c index a1e519793..aaa6ddbe4 100644 --- a/src/http.c +++ b/src/http.c @@ -155,63 +155,6 @@ const unsigned char http_char_classes[256] = { [127] = HTTP_FLG_CTL, }; -const struct ist HTTP_100 = IST("HTTP/1.1 100 Continue\r\n\r\n"); - -const struct ist HTTP_103 = IST("HTTP/1.1 103 Early Hints\r\n"); - -/* Warning: no "connection" header is provided with the 3xx messages below */ -const char *HTTP_301 = - "HTTP/1.1 301 Moved Permanently\r\n" - "Content-length: 0\r\n" - "Location: "; /* not terminated since it will be concatenated with the URL */ - -const char *HTTP_302 = - "HTTP/1.1 302 Found\r\n" - "Cache-Control: no-cache\r\n" - "Content-length: 0\r\n" - "Location: "; /* not terminated since it will be concatenated with the URL */ - -/* same as 302 except that the browser MUST retry with the GET method */ -const char *HTTP_303 = - "HTTP/1.1 303 See Other\r\n" - "Cache-Control: no-cache\r\n" - "Content-length: 0\r\n" - "Location: "; /* not terminated since it will be concatenated with the URL */ - -/* same as 302 except that the browser MUST retry with the same method */ -const char *HTTP_307 = - "HTTP/1.1 307 Temporary Redirect\r\n" - "Cache-Control: no-cache\r\n" - "Content-length: 0\r\n" - "Location: "; /* not terminated since it will be concatenated with the URL */ - -/* same as 301 except that the browser MUST retry with the same method */ -const char *HTTP_308 = - "HTTP/1.1 308 Permanent Redirect\r\n" - "Content-length: 0\r\n" - "Location: "; /* not terminated since it will be concatenated with the URL */ - -/* Warning: this one is an sprintf() fmt string, with as its only argument */ -const char *HTTP_401_fmt = - "HTTP/1.1 401 Unauthorized\r\n" - "Content-length: 112\r\n" - "Cache-Control: no-cache\r\n" - "Connection: close\r\n" - "Content-Type: text/html\r\n" - "WWW-Authenticate: Basic realm=\"%s\"\r\n" - "\r\n" - "

401 Unauthorized

\nYou need a valid user and password to access this content.\n\n"; - -const char *HTTP_407_fmt = - "HTTP/1.1 407 Unauthorized\r\n" - "Content-length: 112\r\n" - "Cache-Control: no-cache\r\n" - "Connection: close\r\n" - "Content-Type: text/html\r\n" - "Proxy-Authenticate: Basic realm=\"%s\"\r\n" - "\r\n" - "

407 Unauthorized

\nYou need a valid user and password to access this content.\n\n"; - const int http_err_codes[HTTP_ERR_SIZE] = { [HTTP_ERR_200] = 200, /* used by "monitor-uri" */ [HTTP_ERR_400] = 400, diff --git a/src/http_htx.c b/src/http_htx.c index 3137fbebb..7211a4de1 100644 --- a/src/http_htx.c +++ b/src/http_htx.c @@ -1223,6 +1223,17 @@ struct buffer *http_parse_errorfile(int status, const char *file, char **errmsg) */ struct buffer *http_parse_errorloc(int errloc, int status, const char *url, char **errmsg) { + static const char *HTTP_302 = + "HTTP/1.1 302 Found\r\n" + "Cache-Control: no-cache\r\n" + "Content-length: 0\r\n" + "Location: "; /* not terminated since it will be concatenated with the URL */ + static const char *HTTP_303 = + "HTTP/1.1 303 See Other\r\n" + "Cache-Control: no-cache\r\n" + "Content-length: 0\r\n" + "Location: "; /* not terminated since it will be concatenated with the URL */ + struct buffer *buf = NULL; const char *msg; char *key = NULL, *err = NULL;