]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] checks: make the HTTP check code add the CRLF itself
authorWilly Tarreau <w@1wt.eu>
Wed, 27 Jan 2010 10:28:42 +0000 (11:28 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 28 Jan 2010 22:16:59 +0000 (23:16 +0100)
Currently we cannot easily add headers nor anything to HTTP checks
because the requests are pre-formatted with the last CRLF. Make the
check code add the CRLF itself so that we can later add useful info.
(cherry picked from commit e9d8788fddae2dfdb06f84000718cb9b2f5da37c)

include/common/defaults.h
src/cfgparse.c
src/checks.c

index f0873cfae48e13de5888baadff41388500822f3d..ae91d322b5b6ee555b043361388e248d92bbdf39 100644 (file)
 #define        DEF_CHKINTR     2000
 #define DEF_FALLTIME    3
 #define DEF_RISETIME    2
-#define DEF_CHECK_REQ   "OPTIONS / HTTP/1.0\r\n\r\n"
+#define DEF_CHECK_REQ   "OPTIONS / HTTP/1.0\r\n"
 #define DEF_SMTP_CHECK_REQ   "HELO localhost\r\n"
 
 // X-Forwarded-For header default
index 8903a820521ea045d35cf20711a065e4665f8281..4765a527dbb6c73de90266377b9df2efae3048c1 100644 (file)
@@ -2015,12 +2015,12 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                                curproxy->check_req = strdup(DEF_CHECK_REQ); /* default request */
                                curproxy->check_len = strlen(DEF_CHECK_REQ);
                        } else if (!*args[3]) { /* one argument : URI */
-                               int reqlen = strlen(args[2]) + strlen("OPTIONS  HTTP/1.0\r\n\r\n") + 1;
+                               int reqlen = strlen(args[2]) + strlen("OPTIONS  HTTP/1.0\r\n") + 1;
                                curproxy->check_req = (char *)malloc(reqlen);
                                curproxy->check_len = snprintf(curproxy->check_req, reqlen,
-                                                              "OPTIONS %s HTTP/1.0\r\n\r\n", args[2]); /* URI to use */
+                                                              "OPTIONS %s HTTP/1.0\r\n", args[2]); /* URI to use */
                        } else { /* more arguments : METHOD URI [HTTP_VER] */
-                               int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n\r\n");
+                               int reqlen = strlen(args[2]) + strlen(args[3]) + 3 + strlen("\r\n");
                                if (*args[4])
                                        reqlen += strlen(args[4]);
                                else
@@ -2028,7 +2028,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                    
                                curproxy->check_req = (char *)malloc(reqlen);
                                curproxy->check_len = snprintf(curproxy->check_req, reqlen,
-                                                              "%s %s %s\r\n\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0");
+                                                              "%s %s %s\r\n", args[2], args[3], *args[4]?args[4]:"HTTP/1.0");
                        }
                }
                else if (!strcmp(args[1], "ssl-hello-chk")) {
index a7facf0da8fc6dc3bf586a8ff412bd0bf286030c..5445b8831bc81b5df7a0613a228e61e74fbf6c11 100644 (file)
@@ -349,6 +349,9 @@ static int event_srv_chk_w(int fd)
                    (s->proxy->options & PR_O_SSL3_CHK) ||
                    (s->proxy->options & PR_O_SMTP_CHK)) {
                        int ret;
+                       const char *check_req = s->proxy->check_req;
+                       int check_len = s->proxy->check_len;
+
                        /* we want to check if this host replies to HTTP or SSLv3 requests
                         * so we'll send the request, and won't wake the checker up now.
                         */
@@ -358,9 +361,16 @@ static int event_srv_chk_w(int fd)
                                int gmt_time = htonl(date.tv_sec);
                                memcpy(s->proxy->check_req + 11, &gmt_time, 4);
                        }
+                       else if (s->proxy->options & PR_O_HTTP_CHK) {
+                               memcpy(trash, check_req, check_len);
+                               trash[check_len++] = '\r';
+                               trash[check_len++] = '\n';
+                               trash[check_len] = '\0';
+                               check_req = trash;
+                       }
 
-                       ret = send(fd, s->proxy->check_req, s->proxy->check_len, MSG_DONTWAIT | MSG_NOSIGNAL);
-                       if (ret == s->proxy->check_len) {
+                       ret = send(fd, check_req, check_len, MSG_DONTWAIT | MSG_NOSIGNAL);
+                       if (ret == check_len) {
                                /* we allow up to <timeout.check> if nonzero for a responce */
                                if (s->proxy->timeout.check)
                                        t->expire = tick_add_ifset(now_ms, s->proxy->timeout.check);