---
 libavformat/http.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 579debc..dcbd33a 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -332,15 +332,22 @@ int ff_http_do_new_request(URLContext *h, const char *uri)
         return AVERROR(EINVAL);
     }
 
+    if (!s->end_header) {
+        int new_location;
+        http_read_header(h, &new_location);
+        if (s->willclose) {
+            ret = ffurl_closep(&s->hd);
+            if (ret < 0)
+                return ret;
+        }
+    }
+
     if (!s->end_chunked_post) {
         ret = http_shutdown(h, h->flags);
         if (ret < 0)
             return ret;
     }
 
-    if (s->willclose)
-        return AVERROR_EOF;
-
     s->end_chunked_post = 0;
     s->chunkend      = 0;
     s->off           = 0;
-- 
2.7.4
