]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: http: implement redirect 307 and 308
authorYves Lafon <ylafon@w3.org>
Mon, 11 Mar 2013 15:06:05 +0000 (11:06 -0400)
committerWilly Tarreau <w@1wt.eu>
Fri, 29 Mar 2013 18:17:41 +0000 (19:17 +0100)
I needed to emit a 307 and noticed it was not available so I did it,
as well as 308.

src/proto_http.c

index 4644acfc339f578e2f03c91712460573934c19d8..24e0a766307ed05f74627cdadbec054d020a4632 100644 (file)
@@ -92,6 +92,20 @@ const char *HTTP_303 =
        "Content-length: 0\r\n"
        "Location: "; /* not terminated since it will be concatenated with the URL */
 
+
+/* same as 302 except that the browser MUST retry with the same method */
+const char *HTTP_307 =
+       "HTTP/1.1 307 Temporary Redirect\r\n"
+       "Cache-Control: no-cache\r\n"
+       "Content-length: 0\r\n"
+       "Location: "; /* not terminated since it will be concatenated with the URL */
+
+/* same as 301 except that the browser MUST retry with the same method */
+const char *HTTP_308 =
+       "HTTP/1.1 308 Permanent Redirect\r\n"
+       "Content-length: 0\r\n"
+       "Location: "; /* not terminated since it will be concatenated with the URL */
+
 /* Warning: this one is an sprintf() fmt string, with <realm> as its only argument */
 const char *HTTP_401_fmt =
        "HTTP/1.0 401 Unauthorized\r\n"
@@ -3140,6 +3154,12 @@ static int http_apply_redirect_rule(struct redirect_rule *rule, struct session *
 
        /* build redirect message */
        switch(rule->code) {
+       case 308:
+               msg_fmt = HTTP_308;
+               break;
+       case 307:
+               msg_fmt = HTTP_307;
+               break;
        case 303:
                msg_fmt = HTTP_303;
                break;
@@ -8228,9 +8248,9 @@ struct redirect_rule *http_parse_redirect_rule(const char *file, int linenum, st
 
                        cur_arg++;
                        code = atol(args[cur_arg]);
-                       if (code < 301 || code > 303) {
+                       if (code < 301 || code > 308 || (code > 303 && code < 307)) {
                                memprintf(errmsg,
-                                         "'%s': unsupported HTTP code '%s' (must be a number between 301 and 303)",
+                                         "'%s': unsupported HTTP code '%s' (must be one of 301, 302, 303, 307 or 308)",
                                          args[cur_arg - 1], args[cur_arg]);
                                return NULL;
                        }