From 11d7a034111c1b6c7882dc12ebedd15ff5a7a94e Mon Sep 17 00:00:00 2001 From: eadler Date: Mon, 29 Oct 2012 04:16:52 +0000 Subject: [PATCH] MFC r241840: Don't deny non-temporary redirects if the -A option is set (per the man page) [0] While here add support for draft-reschke-http-status-308-07 PR: 172451 [0] Approved by: cperciva (implicit) git-svn-id: svn://svn.freebsd.org/base/stable/9@242289 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- lib/libfetch/http.c | 14 ++++++++++++-- lib/libfetch/http.errors | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/libfetch/http.c b/lib/libfetch/http.c index 5c3001c86..916ebd09f 100644 --- a/lib/libfetch/http.c +++ b/lib/libfetch/http.c @@ -96,6 +96,7 @@ __FBSDID("$FreeBSD$"); #define HTTP_SEE_OTHER 303 #define HTTP_NOT_MODIFIED 304 #define HTTP_TEMP_REDIRECT 307 +#define HTTP_PERM_REDIRECT 308 #define HTTP_NEED_AUTH 401 #define HTTP_NEED_PROXY_AUTH 407 #define HTTP_BAD_RANGE 416 @@ -1516,8 +1517,7 @@ http_request(struct url *URL, const char *op, struct url_stat *us, /* try the provided URL first */ url = URL; - /* if the A flag is set, we only get one try */ - n = noredirect ? 1 : MAX_REDIRECT; + n = MAX_REDIRECT; i = 0; e = HTTP_PROTOCOL_ERROR; @@ -1764,6 +1764,16 @@ http_request(struct url *URL, const char *op, struct url_stat *us, case hdr_location: if (!HTTP_REDIRECT(conn->err)) break; + /* + * if the A flag is set, we don't follow + * temporary redirects. + */ + if (noredirect && + conn->err != HTTP_MOVED_PERM && + conn->err != HTTP_PERM_REDIRECT) { + n = 1; + break; + } if (new) free(new); if (verbose) diff --git a/lib/libfetch/http.errors b/lib/libfetch/http.errors index 1f38574d4..e5389fefc 100644 --- a/lib/libfetch/http.errors +++ b/lib/libfetch/http.errors @@ -18,6 +18,7 @@ 304 OK Not Modified 305 INFO Use Proxy 307 MOVED Temporary Redirect +308 MOVED Permanent Redirect 400 PROTO Bad Request 401 AUTH Unauthorized 402 AUTH Payment Required -- 2.45.0