]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] add configuration support for "redir" server keyword
authorWilly Tarreau <w@1wt.eu>
Tue, 12 Feb 2008 22:16:33 +0000 (23:16 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 12 Feb 2008 23:55:49 +0000 (00:55 +0100)
The servers now support the "redir" keyword, making it possible to
return a 302 with the specified prefix in front of the request instead
of connecting to them. This is generally useful for multi-site load
balancing but may also serve in order to achieve very high traffic
rate.

The keyword has only been added to the config parser and to structures,
it's not used yet.

include/types/server.h
src/cfgparse.c

index cfc4d7d832515b761174f5355d66569d3e2855b8..c93236cb45a5984b27e00a3904c428354dd332b7 100644 (file)
@@ -2,7 +2,7 @@
   include/types/server.h
   This file defines everything related to servers.
 
-  Copyright (C) 2000-2007 Willy Tarreau - w@1wt.eu
+  Copyright (C) 2000-2008 Willy Tarreau - w@1wt.eu
   
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -73,7 +73,9 @@ struct server {
        int state;                              /* server state (SRV_*) */
        int prev_state;                         /* server state before last change (SRV_*) */
        int  cklen;                             /* the len of the cookie, to speed up checks */
+       int rdr_len;                            /* the length of the redirection prefix */
        char *cookie;                           /* the id set in the cookie */
+       char *rdr_pfx;                          /* the redirection prefix */
 
        struct proxy *proxy;                    /* the proxy this server belongs to */
        int cur_sess, cur_sess_max;             /* number of currently active sessions (including syn_sent) */
index 1815ed4871057d83589d351062f6b368cadae161..9329df3eb3c1a19900d9f293e27c5149920d253e 100644 (file)
@@ -1547,6 +1547,11 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                                newsrv->cklen = strlen(args[cur_arg + 1]);
                                cur_arg += 2;
                        }
+                       else if (!strcmp(args[cur_arg], "redir")) {
+                               newsrv->rdr_pfx = strdup(args[cur_arg + 1]);
+                               newsrv->rdr_len = strlen(args[cur_arg + 1]);
+                               cur_arg += 2;
+                       }
                        else if (!strcmp(args[cur_arg], "rise")) {
                                newsrv->rise = atol(args[cur_arg + 1]);
                                newsrv->health = newsrv->rise;
@@ -1691,7 +1696,7 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
                                return -1;
                        }
                        else {
-                               Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'check', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'addr', 'port', 'source', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n",
+                               Alert("parsing [%s:%d] : server %s only supports options 'backup', 'cookie', 'redir', 'check', 'inter', 'fastinter', 'downinter', 'rise', 'fall', 'addr', 'port', 'source', 'minconn', 'maxconn', 'maxqueue', 'slowstart' and 'weight'.\n",
                                      file, linenum, newsrv->id);
                                return -1;
                        }
@@ -2904,6 +2909,19 @@ int readcfgfile(const char *file)
                if (curproxy->options & PR_O_LOGASAP)
                        curproxy->to_log &= ~LW_BYTES;
 
+               /*
+                * ensure that we're not cross-dressing a TCP server into HTTP.
+                */
+               newsrv = curproxy->srv;
+               while (newsrv != NULL) {
+                       if ((curproxy->mode != PR_MODE_HTTP) && (newsrv->rdr_len || newsrv->cklen)) {
+                               Alert("parsing %s, %s '%s' : server cannot have cookie or redirect prefix in non-HTTP mode.\n",
+                                     file, proxy_type_str(curproxy), curproxy->id, linenum);
+                               goto err;
+                       }
+                       newsrv = newsrv->next;
+               }
+
                /*
                 * If this server supports a maxconn parameter, it needs a dedicated
                 * tasks to fill the emptied slots when a connection leaves.