OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

205 lines
7.8 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../pound/pound-2.3.2-custom-redirect.patch
  5. # Copyright (C) 2008 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. Author: Chris Barnett <barn3y(at)gmail.com>
  17. Initial Package Version: 2.3.2
  18. Origin: http://www.apsis.ch/pound/pound_list/archive/2007/2007-09/1190613609000#1190613609000
  19. Description: This patch adds the capability to configure 301 or 307 redirects.
  20. Usage Information:
  21. You can force a 301 Moved Permanently redirect like this:
  22. ListenHTTP
  23. Address 0.0.0.0
  24. Port 80
  25. Service
  26. HeadRequire "Host: .*www.server0.com.*"
  27. Redirect 301 "http://www.server1.com"
  28. End
  29. End
  30. You can force a 302 Found or 307 Temporary Redirect in the same way.
  31. The existing Redirect syntax still works as expected:
  32. ListenHTTP
  33. Address 0.0.0.0
  34. Port 80
  35. Service
  36. HeadRequire "Host: .*www.server0.com.*"
  37. Redirect "http://www.server1.com"
  38. End
  39. End
  40. Will use a 302 Found redirect.
  41. diff -Naur Pound-2.3.2/config.c Pound-2.3.2-custom-redirect/config.c
  42. --- Pound-2.3.2/config.c 2007-05-18 18:34:53.000000000 +1000
  43. +++ Pound-2.3.2-custom-redirect/config.c 2007-09-24 14:51:40.000000000 +1000
  44. @@ -425,7 +425,9 @@
  45. be->alive = 1;
  46. pthread_mutex_init(&res->mut, NULL);
  47. lin[matches[1].rm_eo] = '\0';
  48. - if((be->url = strdup(lin + matches[1].rm_so)) == NULL) {
  49. + be->redir_type = atoi(lin + matches[1].rm_so);
  50. + lin[matches[3].rm_eo] = '\0';
  51. + if((be->url = strdup(lin + matches[3].rm_so)) == NULL) {
  52. logmsg(LOG_ERR, "line %d: Redirector config: out of memory - aborted", n_lin);
  53. exit(1);
  54. }
  55. @@ -1083,7 +1085,7 @@
  56. || regcomp(&TimeOut, "^[ \t]*TimeOut[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
  57. || regcomp(&HAport, "^[ \t]*HAport[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
  58. || regcomp(&HAportAddr, "^[ \t]*HAport[ \t]+([^ \t]+)[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
  59. - || regcomp(&Redirect, "^[ \t]*Redirect[ \t]+\"(.+)\"[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
  60. + || regcomp(&Redirect, "^[ \t]*Redirect[ \t]+((301|302|307)[ \t]+)?\"(.+)\"[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
  61. || regcomp(&Session, "^[ \t]*Session[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
  62. || regcomp(&Type, "^[ \t]*Type[ \t]+([^ \t]+)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
  63. || regcomp(&TTL, "^[ \t]*TTL[ \t]+([1-9][0-9]*)[ \t]*$", REG_ICASE | REG_NEWLINE | REG_EXTENDED)
  64. diff -Naur Pound-2.3.2/http.c Pound-2.3.2-custom-redirect/http.c
  65. --- Pound-2.3.2/http.c 2007-05-18 18:34:53.000000000 +1000
  66. +++ Pound-2.3.2-custom-redirect/http.c 2007-09-24 15:07:20.000000000 +1000
  67. @@ -52,23 +52,32 @@
  68. * Reply with a redirect
  69. */
  70. static void
  71. -redirect_reply(BIO *const c, const char *url)
  72. +redirect_reply(BIO *const c, const int redir_type, const char *url)
  73. {
  74. char rep[MAXBUF], cont[MAXBUF];
  75. + char *type_str;
  76. snprintf(cont, sizeof(cont),
  77. "<html><head><title>Redirect</title></head><body><h1>Redirect</h1><p>You should go to <a href=\"%s\">%s</a></p></body></html>",
  78. url, url);
  79. - /*
  80. - * This really should be 307, but some HTTP/1.0 clients do not understand that, so we use 302
  81. +
  82. + switch(redir_type) {
  83. + case 301:
  84. + type_str = "301 Moved Permanently";
  85. + break;
  86. +
  87. + case 307:
  88. + type_str = "307 Temporary Redirect";
  89. + break;
  90. +
  91. + default:
  92. + type_str = "302 Found";
  93. + break;
  94. + }
  95. snprintf(rep, sizeof(rep),
  96. - "HTTP/1.0 307 Temporary Redirect\r\nLocation: %s\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n",
  97. - url, strlen(cont));
  98. - */
  99. - snprintf(rep, sizeof(rep),
  100. - "HTTP/1.0 302 Found\r\nLocation: %s\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n",
  101. - url, strlen(cont));
  102. + "HTTP/1.0 %s\r\nLocation: %s\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n",
  103. + type_str, url, strlen(cont));
  104. BIO_write(c, rep, strlen(rep));
  105. BIO_write(c, cont, strlen(cont));
  106. BIO_flush(c);
  107. @@ -996,7 +1005,7 @@
  108. snprintf(buf, sizeof(buf) - 1, "%s%s", cur_backend->url, url);
  109. else
  110. strncpy(buf, cur_backend->url, sizeof(buf) - 1);
  111. - redirect_reply(cl, buf);
  112. + redirect_reply(cl, cur_backend->redir_type, buf);
  113. addr2str(caddr, MAXBUF - 1, &from_host);
  114. switch(lstn->log_level) {
  115. case 0:
  116. diff -Naur Pound-2.3.2/pound.8 Pound-2.3.2-custom-redirect/pound.8
  117. --- Pound-2.3.2/pound.8 2007-05-18 18:34:53.000000000 +1000
  118. +++ Pound-2.3.2-custom-redirect/pound.8 2007-09-24 15:06:14.000000000 +1000
  119. @@ -544,11 +544,13 @@
  120. .B Pound
  121. will attempt to load-balance between them.
  122. .TP
  123. -\fBRedirect\fR "url"
  124. +\fBRedirect\fR [301|302|307] "url"
  125. This is a special type of back-end. Instead of sending the request to a back-end
  126. .B Pound
  127. -replies immediately with a redirection to the given URL. You may define multiple
  128. -redirectors in a service, as well as mixing them with regular back-ends.
  129. +replies immediately with a redirection to the given URL. You may specify the type
  130. +of redirection used: 301 Moved Permanently, 302 Found (default if none specified),
  131. +or 307 Temporary Redirect. You may define multiple redirectors in a service, as
  132. +well as mixing them with regular back-ends.
  133. .IP
  134. The address the client is redirected to is determined by the actual
  135. .I url
  136. @@ -562,7 +564,7 @@
  137. .br
  138. .br
  139. - Redirect "http://abc.example"
  140. + Redirect 307 "http://abc.example"
  141. .br
  142. .br
  143. @@ -574,7 +576,7 @@
  144. .br
  145. .br
  146. - Redirect "http://abc.example/index.html"
  147. + Redirect 307 "http://abc.example/index.html"
  148. .br
  149. .br
  150. @@ -582,12 +584,11 @@
  151. .IR "http://abc.example/index.html".
  152. .IP
  153. .IR "Technical note":
  154. -in an ideal world
  155. +Ideally, "307 Temporary Redirect" should be used instead of "302 Found".
  156. +Unfortunately, that is not yet supported by all clients (in particular
  157. +HTTP 1.0 ones), so
  158. .B Pound
  159. -should reply with a "307 Temporary Redirect" status. Unfortunately, that is not
  160. -yet supported by all clients (in particular HTTP 1.0 ones), so
  161. -.B Pound
  162. -currently replies with a "302 Found" instead.
  163. +currently defaults to "302 Found" instead.
  164. .TP
  165. \fBEmergency\fR
  166. Directives enclosed between an
  167. @@ -940,7 +941,7 @@
  168. .br
  169. Url "/forbidden.*"
  170. .br
  171. - Redirect "https://xyzzy.com"
  172. + Redirect 302 "https://xyzzy.com"
  173. .br
  174. End
  175. .br
  176. diff -Naur Pound-2.3.2/pound.h Pound-2.3.2-custom-redirect/pound.h
  177. --- Pound-2.3.2/pound.h 2007-05-18 18:34:53.000000000 +1000
  178. +++ Pound-2.3.2-custom-redirect/pound.h 2007-09-24 14:05:30.000000000 +1000
  179. @@ -288,7 +288,8 @@
  180. int priority; /* priority */
  181. int to;
  182. struct sockaddr_in HA; /* HA address & port */
  183. - char *url; /* for redirectors */
  184. + char *url; /* (URL for redirectors) */
  185. + int redir_type; /* redirect type (for redirectors) */
  186. int redir_req; /* the redirect should include the request path */
  187. pthread_mutex_t mut; /* mutex for this back-end */
  188. int n_requests; /* number of requests seen */