From a472d363de12f74848b093144eef298e6f293dfc Mon Sep 17 00:00:00 2001
From: Armin Hasitzka <armin@grabyo.com>
Date: Tue, 1 Oct 2019 12:47:04 +0100
Subject: [PATCH] libavformat/http.c: Fix interpretation of the Location header

Location headers are to be ignored in combination with status codes that are not
201 or 3xx (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Location).
---
 libavformat/http.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 71dd6c2b1f..7baeb616b5 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -983,9 +983,11 @@ static int process_line(URLContext *h, char *line, int line_count,
         while (av_isspace(*p))
             p++;
         if (!av_strcasecmp(tag, "Location")) {
-            if ((ret = parse_location(s, p)) < 0)
-                return ret;
-            *new_location = 1;
+            if (s->http_code == 201 || s->http_code >= 300 && s->http_code < 400) {
+                if ((ret = parse_location(s, p)) < 0)
+                    return ret;
+                *new_location = 1;
+            }
         } else if (!av_strcasecmp(tag, "Content-Length") &&
                    s->filesize == UINT64_MAX) {
             s->filesize = strtoull(p, NULL, 10);
-- 
2.22.0

