]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] http: make the "HTTP 200" status code configurable.
authorWilly Tarreau <w@1wt.eu>
Wed, 11 May 2011 14:28:49 +0000 (16:28 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 11 May 2011 14:31:43 +0000 (16:31 +0200)
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
include/types/proto_http.h
src/proto_http.c

index 2cac15209d6d4f48dd5bd63e1c43b85062701249..00ee8f07233eca0e2557a43ef86e8519bd3a6cb6 100644 (file)
@@ -2075,7 +2075,7 @@ errorfile <code> <file>
                                  yes   |    yes   |   yes  |   yes
   Arguments :
     <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
               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.
   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 <code> <url>
                                  yes   |    yes   |   yes  |   yes
   Arguments :
     <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
               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.
   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 <code> <url>
   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 } <condition>
   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 } <condition>
         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 <source>
index 8dd1d52dc60d7cd67853564465fef32f2e46b59e..3f6724b4a1fcc31a247b119ec130c13d2f165f4e 100644 (file)
@@ -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,
index af8adc92ce9d17943d5c8f7e46634dfce1eb8a04..bdfc113a050b1dabb833007bcf26726c5782662d 100644 (file)
@@ -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"
-       "<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 */
 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"
+       "<html><body><h1>200 OK</h1>\nService ready.\n</body></html>\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;
        }