From ae94d4df8f54c9b48cd06320424eb2fab6e29aa4 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 11 May 2011 16:28:49 +0200 Subject: [PATCH] [MINOR] http: make the "HTTP 200" status code configurable. This status code is used in response to requests matching "monitor-uri". Some users need to adjust it to fit their needs (eg: make some strings appear there). As it's already defined as a chunked string and used exactly like other status codes, it makes sense to make it configurable with the usual "errorfile", "errorloc", ... --- doc/configuration.txt | 15 +++++++++++---- include/types/proto_http.h | 3 ++- src/proto_http.c | 25 ++++++++++--------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/doc/configuration.txt b/doc/configuration.txt index 2cac15209..00ee8f072 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -2075,7 +2075,7 @@ errorfile yes | yes | yes | yes Arguments : is the HTTP status code. Currently, HAProxy is capable of - generating codes 400, 403, 408, 500, 502, 503, and 504. + generating codes 200, 400, 403, 408, 500, 502, 503, and 504. designates a file containing the full HTTP response. It is recommended to follow the common practice of appending ".http" to @@ -2087,6 +2087,8 @@ errorfile errors returned by the server, but errors detected and returned by HAProxy. This is why the list of supported errors is limited to a small set. + Code 200 is emitted in response to requests matching a "monitor-uri" rule. + The files are returned verbatim on the TCP socket. This allows any trick such as redirections to another URL or site, as well as tricks to clean cookies, force enable or disable caching, etc... The package provides default error @@ -2120,7 +2122,7 @@ errorloc302 yes | yes | yes | yes Arguments : is the HTTP status code. Currently, HAProxy is capable of - generating codes 400, 403, 408, 500, 502, 503, and 504. + generating codes 200, 400, 403, 408, 500, 502, 503, and 504. it is the exact contents of the "Location" header. It may contain either a relative URI to an error page hosted on the same site, @@ -2132,6 +2134,8 @@ errorloc302 errors returned by the server, but errors detected and returned by HAProxy. This is why the list of supported errors is limited to a small set. + Code 200 is emitted in response to requests matching a "monitor-uri" rule. + Note that both keyword return the HTTP 302 status code, which tells the client to fetch the designated URL using the same HTTP method. This can be quite problematic in case of non-GET methods such as POST, because the URL @@ -2161,6 +2165,8 @@ errorloc303 errors returned by the server, but errors detected and returned by HAProxy. This is why the list of supported errors is limited to a small set. + Code 200 is emitted in response to requests matching a "monitor-uri" rule. + Note that both keyword return the HTTP 303 status code, which tells the client to fetch the designated URL using the same HTTP GET method. This solves the usual problems associated with "errorloc" and the 302 code. It is @@ -2658,7 +2664,8 @@ monitor fail { if | unless } very useful to report a site failure to an external component which may base routing advertisements between multiple sites on the availability reported by haproxy. In this case, one would rely on an ACL involving the "nbsrv" - criterion. Note that "monitor fail" only works in HTTP mode. + criterion. Note that "monitor fail" only works in HTTP mode. Both status + messages may be tweaked using "errorfile" or "errorloc" if needed. Example: frontend www @@ -2668,7 +2675,7 @@ monitor fail { if | unless } monitor-uri /site_alive monitor fail if site_dead - See also : "monitor-net", "monitor-uri" + See also : "monitor-net", "monitor-uri", "errorfile", "errorloc" monitor-net diff --git a/include/types/proto_http.h b/include/types/proto_http.h index 8dd1d52dc..3f6724b4a 100644 --- a/include/types/proto_http.h +++ b/include/types/proto_http.h @@ -240,7 +240,8 @@ enum { * All implemented return codes */ enum { - HTTP_ERR_400 = 0, + HTTP_ERR_200 = 0, + HTTP_ERR_400, HTTP_ERR_403, HTTP_ERR_408, HTTP_ERR_500, diff --git a/src/proto_http.c b/src/proto_http.c index af8adc92c..bdfc113a0 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -68,20 +68,6 @@ const struct chunk http_100_chunk = { .len = sizeof(HTTP_100)-1 }; -/* This is used by remote monitoring */ -const char HTTP_200[] = - "HTTP/1.0 200 OK\r\n" - "Cache-Control: no-cache\r\n" - "Connection: close\r\n" - "Content-Type: text/html\r\n" - "\r\n" - "

200 OK

\nService ready.\n\n"; - -const struct chunk http_200_chunk = { - .str = (char *)&HTTP_200, - .len = sizeof(HTTP_200)-1 -}; - /* Warning: no "connection" header is provided with the 3xx messages below */ const char *HTTP_301 = "HTTP/1.1 301 Moved Permanently\r\n" @@ -123,6 +109,7 @@ const char *HTTP_407_fmt = const int http_err_codes[HTTP_ERR_SIZE] = { + [HTTP_ERR_200] = 200, /* used by "monitor-uri" */ [HTTP_ERR_400] = 400, [HTTP_ERR_403] = 403, [HTTP_ERR_408] = 408, @@ -133,6 +120,14 @@ const int http_err_codes[HTTP_ERR_SIZE] = { }; static const char *http_err_msgs[HTTP_ERR_SIZE] = { + [HTTP_ERR_200] = + "HTTP/1.0 200 OK\r\n" + "Cache-Control: no-cache\r\n" + "Connection: close\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "

200 OK

\nService ready.\n\n", + [HTTP_ERR_400] = "HTTP/1.0 400 Bad request\r\n" "Cache-Control: no-cache\r\n" @@ -2705,7 +2700,7 @@ int http_wait_for_request(struct session *s, struct buffer *req, int an_bit) /* nothing to fail, let's reply normaly */ txn->status = 200; - stream_int_retnclose(req->prod, &http_200_chunk); + stream_int_retnclose(req->prod, error_message(s, HTTP_ERR_200)); goto return_prx_cond; }