mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-08 08:07:10 +02:00
[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", ...
This commit is contained in:
parent
436d9ed808
commit
ae94d4df8f
@ -2075,7 +2075,7 @@ errorfile <code> <file>
|
|||||||
yes | yes | yes | yes
|
yes | yes | yes | yes
|
||||||
Arguments :
|
Arguments :
|
||||||
<code> is the HTTP status code. Currently, HAProxy is capable of
|
<code> 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.
|
||||||
|
|
||||||
<file> designates a file containing the full HTTP response. It is
|
<file> designates a file containing the full HTTP response. It is
|
||||||
recommended to follow the common practice of appending ".http" to
|
recommended to follow the common practice of appending ".http" to
|
||||||
@ -2087,6 +2087,8 @@ errorfile <code> <file>
|
|||||||
errors returned by the server, but errors detected and returned by HAProxy.
|
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.
|
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
|
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,
|
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
|
force enable or disable caching, etc... The package provides default error
|
||||||
@ -2120,7 +2122,7 @@ errorloc302 <code> <url>
|
|||||||
yes | yes | yes | yes
|
yes | yes | yes | yes
|
||||||
Arguments :
|
Arguments :
|
||||||
<code> is the HTTP status code. Currently, HAProxy is capable of
|
<code> 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.
|
||||||
|
|
||||||
<url> it is the exact contents of the "Location" header. It may contain
|
<url> 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,
|
either a relative URI to an error page hosted on the same site,
|
||||||
@ -2132,6 +2134,8 @@ errorloc302 <code> <url>
|
|||||||
errors returned by the server, but errors detected and returned by HAProxy.
|
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.
|
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
|
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
|
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
|
quite problematic in case of non-GET methods such as POST, because the URL
|
||||||
@ -2161,6 +2165,8 @@ errorloc303 <code> <url>
|
|||||||
errors returned by the server, but errors detected and returned by HAProxy.
|
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.
|
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
|
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
|
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
|
solves the usual problems associated with "errorloc" and the 302 code. It is
|
||||||
@ -2658,7 +2664,8 @@ monitor fail { if | unless } <condition>
|
|||||||
very useful to report a site failure to an external component which may base
|
very useful to report a site failure to an external component which may base
|
||||||
routing advertisements between multiple sites on the availability reported by
|
routing advertisements between multiple sites on the availability reported by
|
||||||
haproxy. In this case, one would rely on an ACL involving the "nbsrv"
|
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:
|
Example:
|
||||||
frontend www
|
frontend www
|
||||||
@ -2668,7 +2675,7 @@ monitor fail { if | unless } <condition>
|
|||||||
monitor-uri /site_alive
|
monitor-uri /site_alive
|
||||||
monitor fail if site_dead
|
monitor fail if site_dead
|
||||||
|
|
||||||
See also : "monitor-net", "monitor-uri"
|
See also : "monitor-net", "monitor-uri", "errorfile", "errorloc"
|
||||||
|
|
||||||
|
|
||||||
monitor-net <source>
|
monitor-net <source>
|
||||||
|
@ -240,7 +240,8 @@ enum {
|
|||||||
* All implemented return codes
|
* All implemented return codes
|
||||||
*/
|
*/
|
||||||
enum {
|
enum {
|
||||||
HTTP_ERR_400 = 0,
|
HTTP_ERR_200 = 0,
|
||||||
|
HTTP_ERR_400,
|
||||||
HTTP_ERR_403,
|
HTTP_ERR_403,
|
||||||
HTTP_ERR_408,
|
HTTP_ERR_408,
|
||||||
HTTP_ERR_500,
|
HTTP_ERR_500,
|
||||||
|
@ -68,20 +68,6 @@ const struct chunk http_100_chunk = {
|
|||||||
.len = sizeof(HTTP_100)-1
|
.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"
|
|
||||||
"<html><body><h1>200 OK</h1>\nService ready.\n</body></html>\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 */
|
/* Warning: no "connection" header is provided with the 3xx messages below */
|
||||||
const char *HTTP_301 =
|
const char *HTTP_301 =
|
||||||
"HTTP/1.1 301 Moved Permanently\r\n"
|
"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] = {
|
const int http_err_codes[HTTP_ERR_SIZE] = {
|
||||||
|
[HTTP_ERR_200] = 200, /* used by "monitor-uri" */
|
||||||
[HTTP_ERR_400] = 400,
|
[HTTP_ERR_400] = 400,
|
||||||
[HTTP_ERR_403] = 403,
|
[HTTP_ERR_403] = 403,
|
||||||
[HTTP_ERR_408] = 408,
|
[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] = {
|
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"
|
||||||
|
"<html><body><h1>200 OK</h1>\nService ready.\n</body></html>\n",
|
||||||
|
|
||||||
[HTTP_ERR_400] =
|
[HTTP_ERR_400] =
|
||||||
"HTTP/1.0 400 Bad request\r\n"
|
"HTTP/1.0 400 Bad request\r\n"
|
||||||
"Cache-Control: no-cache\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 */
|
/* nothing to fail, let's reply normaly */
|
||||||
txn->status = 200;
|
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;
|
goto return_prx_cond;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user