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.
This commit is contained in:
Christopher Faulet 2020-05-27 10:11:59 +02:00
parent b304883754
commit 0bac4cdf1a
3 changed files with 11 additions and 67 deletions

View File

@ -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 struct ist http_known_methods[HTTP_METH_OTHER];
extern const uint8_t http_char_classes[256]; 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); enum http_meth_t find_http_meth(const char *str, const int len);
int http_get_status_idx(unsigned int status); int http_get_status_idx(unsigned int status);
const char *http_get_reason(unsigned int status); const char *http_get_reason(unsigned int status);

View File

@ -155,63 +155,6 @@ const unsigned char http_char_classes[256] = {
[127] = HTTP_FLG_CTL, [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 <realm> 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"
"<html><body><h1>401 Unauthorized</h1>\nYou need a valid user and password to access this content.\n</body></html>\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"
"<html><body><h1>407 Unauthorized</h1>\nYou need a valid user and password to access this content.\n</body></html>\n";
const int http_err_codes[HTTP_ERR_SIZE] = { const int http_err_codes[HTTP_ERR_SIZE] = {
[HTTP_ERR_200] = 200, /* used by "monitor-uri" */ [HTTP_ERR_200] = 200, /* used by "monitor-uri" */
[HTTP_ERR_400] = 400, [HTTP_ERR_400] = 400,

View File

@ -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) 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; struct buffer *buf = NULL;
const char *msg; const char *msg;
char *key = NULL, *err = NULL; char *key = NULL, *err = NULL;