diff --git a/network/pound/pound-2.3.2-custom-redirect.patch b/network/pound/pound-2.3.2-custom-redirect.patch new file mode 100644 index 000000000..382aa205e --- /dev/null +++ b/network/pound/pound-2.3.2-custom-redirect.patch @@ -0,0 +1,205 @@ +# --- SDE-COPYRIGHT-NOTE-BEGIN --- +# This copyright note is auto-generated by ./scripts/Create-CopyPatch. +# +# Filename: package/.../pound/pound-2.3.2-custom-redirect.patch +# Copyright (C) 2008 The OpenSDE Project +# +# More information can be found in the files COPYING and README. +# +# This patch file is dual-licensed. It is available under the license the +# patched project is licensed under, as long as it is an OpenSource license +# as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms +# of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# --- SDE-COPYRIGHT-NOTE-END --- + +Author: Chris Barnett +Initial Package Version: 2.3.2 +Origin: http://www.apsis.ch/pound/pound_list/archive/2007/2007-09/1190613609000#1190613609000 +Description: This patch adds the capability to configure 301 or 307 redirects. + +Usage Information: + +You can force a 301 Moved Permanently redirect like this: + + ListenHTTP + Address 0.0.0.0 + Port 80 + + Service + HeadRequire "Host: .*www.server0.com.*" + Redirect 301 "http://www.server1.com" + End + End + +You can force a 302 Found or 307 Temporary Redirect in the same way. + +The existing Redirect syntax still works as expected: + + ListenHTTP + Address 0.0.0.0 + Port 80 + + Service + HeadRequire "Host: .*www.server0.com.*" + Redirect "http://www.server1.com" + End + End + +Will use a 302 Found redirect. + +diff -Naur Pound-2.3.2/config.c Pound-2.3.2-custom-redirect/config.c +--- Pound-2.3.2/config.c 2007-05-18 18:34:53.000000000 +1000 ++++ Pound-2.3.2-custom-redirect/config.c 2007-09-24 14:51:40.000000000 +1000 +@@ -425,7 +425,9 @@ + be->alive = 1; + pthread_mutex_init(&res->mut, NULL); + lin[matches[1].rm_eo] = '\0'; +- if((be->url = strdup(lin + matches[1].rm_so)) == NULL) { ++ be->redir_type = atoi(lin + matches[1].rm_so); ++ lin[matches[3].rm_eo] = '\0'; ++ if((be->url = strdup(lin + matches[3].rm_so)) == NULL) { + logmsg(LOG_ERR, "line %d: Redirector config: out of memory - aborted", n_lin); + exit(1); + } +@@ -1083,7 +1085,7 @@ + || regcomp(&TimeOut, "^[ \t]*TimeOut[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED) + || regcomp(&HAport, "^[ \t]*HAport[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED) + || regcomp(&HAportAddr, "^[ \t]*HAport[ \t]+([^ \t]+)[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED) +- || regcomp(&Redirect, "^[ \t]*Redirect[ \t]+\"(.+)\"[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED) ++ || regcomp(&Redirect, "^[ \t]*Redirect[ \t]+((301|302|307)[ \t]+)?\"(.+)\"[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED) + || regcomp(&Session, "^[ \t]*Session[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED) + || regcomp(&Type, "^[ \t]*Type[ \t]+([^ \t]+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED) + || regcomp(&TTL, "^[ \t]*TTL[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED) +diff -Naur Pound-2.3.2/http.c Pound-2.3.2-custom-redirect/http.c +--- Pound-2.3.2/http.c 2007-05-18 18:34:53.000000000 +1000 ++++ Pound-2.3.2-custom-redirect/http.c 2007-09-24 15:07:20.000000000 +1000 +@@ -52,23 +52,32 @@ + * Reply with a redirect + */ + static void +-redirect_reply(BIO *const c, const char *url) ++redirect_reply(BIO *const c, const int redir_type, const char *url) + { + char rep[MAXBUF], cont[MAXBUF]; ++ char *type_str; + + snprintf(cont, sizeof(cont), + "Redirect

Redirect

You should go to %s

", + url, url); +- /* +- * This really should be 307, but some HTTP/1.0 clients do not understand that, so we use 302 ++ ++ switch(redir_type) { ++ case 301: ++ type_str = "301 Moved Permanently"; ++ break; ++ ++ case 307: ++ type_str = "307 Temporary Redirect"; ++ break; ++ ++ default: ++ type_str = "302 Found"; ++ break; ++ } + + snprintf(rep, sizeof(rep), +- "HTTP/1.0 307 Temporary Redirect\r\nLocation: %s\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n", +- url, strlen(cont)); +- */ +- snprintf(rep, sizeof(rep), +- "HTTP/1.0 302 Found\r\nLocation: %s\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n", +- url, strlen(cont)); ++ "HTTP/1.0 %s\r\nLocation: %s\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n", ++ type_str, url, strlen(cont)); + BIO_write(c, rep, strlen(rep)); + BIO_write(c, cont, strlen(cont)); + BIO_flush(c); +@@ -996,7 +1005,7 @@ + snprintf(buf, sizeof(buf) - 1, "%s%s", cur_backend->url, url); + else + strncpy(buf, cur_backend->url, sizeof(buf) - 1); +- redirect_reply(cl, buf); ++ redirect_reply(cl, cur_backend->redir_type, buf); + addr2str(caddr, MAXBUF - 1, &from_host); + switch(lstn->log_level) { + case 0: +diff -Naur Pound-2.3.2/pound.8 Pound-2.3.2-custom-redirect/pound.8 +--- Pound-2.3.2/pound.8 2007-05-18 18:34:53.000000000 +1000 ++++ Pound-2.3.2-custom-redirect/pound.8 2007-09-24 15:06:14.000000000 +1000 +@@ -544,11 +544,13 @@ + .B Pound + will attempt to load-balance between them. + .TP +-\fBRedirect\fR "url" ++\fBRedirect\fR [301|302|307] "url" + This is a special type of back-end. Instead of sending the request to a back-end + .B Pound +-replies immediately with a redirection to the given URL. You may define multiple +-redirectors in a service, as well as mixing them with regular back-ends. ++replies immediately with a redirection to the given URL. You may specify the type ++of redirection used: 301 Moved Permanently, 302 Found (default if none specified), ++or 307 Temporary Redirect. You may define multiple redirectors in a service, as ++well as mixing them with regular back-ends. + .IP + The address the client is redirected to is determined by the actual + .I url +@@ -562,7 +564,7 @@ + .br + + .br +- Redirect "http://abc.example" ++ Redirect 307 "http://abc.example" + .br + + .br +@@ -574,7 +576,7 @@ + .br + + .br +- Redirect "http://abc.example/index.html" ++ Redirect 307 "http://abc.example/index.html" + .br + + .br +@@ -582,12 +584,11 @@ + .IR "http://abc.example/index.html". + .IP + .IR "Technical note": +-in an ideal world ++Ideally, "307 Temporary Redirect" should be used instead of "302 Found". ++Unfortunately, that is not yet supported by all clients (in particular ++HTTP 1.0 ones), so + .B Pound +-should reply with a "307 Temporary Redirect" status. Unfortunately, that is not +-yet supported by all clients (in particular HTTP 1.0 ones), so +-.B Pound +-currently replies with a "302 Found" instead. ++currently defaults to "302 Found" instead. + .TP + \fBEmergency\fR + Directives enclosed between an +@@ -940,7 +941,7 @@ + .br + Url "/forbidden.*" + .br +- Redirect "https://xyzzy.com" ++ Redirect 302 "https://xyzzy.com" + .br + End + .br +diff -Naur Pound-2.3.2/pound.h Pound-2.3.2-custom-redirect/pound.h +--- Pound-2.3.2/pound.h 2007-05-18 18:34:53.000000000 +1000 ++++ Pound-2.3.2-custom-redirect/pound.h 2007-09-24 14:05:30.000000000 +1000 +@@ -288,7 +288,8 @@ + int priority; /* priority */ + int to; + struct sockaddr_in HA; /* HA address & port */ +- char *url; /* for redirectors */ ++ char *url; /* (URL for redirectors) */ ++ int redir_type; /* redirect type (for redirectors) */ + int redir_req; /* the redirect should include the request path */ + pthread_mutex_t mut; /* mutex for this back-end */ + int n_requests; /* number of requests seen */