From 3e8d1ae2d25d3fae659fc560506af2ae9b20da12 Mon Sep 17 00:00:00 2001 From: Yves Lafon Date: Mon, 11 Mar 2013 11:06:05 -0400 Subject: [PATCH] MEDIUM: http: implement redirect 307 and 308 I needed to emit a 307 and noticed it was not available so I did it, as well as 308. --- src/proto_http.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/proto_http.c b/src/proto_http.c index 4644acfc3..24e0a7663 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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 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; }