[FFmpeg-devel] [PATCH 1/2] libavformat/http: Use http_read_header in http_shutdown to react to response errors

Basel Sayeh basel.sayeh at hotmail.com
Sun Dec 11 03:09:51 EET 2022


Use http_read_header to parse and print/react to errors in http_shutdown if
 the http server responds with an error (404/500/...)

Signed-off-by: Basel Sayeh <basel.sayeh at hotmail.com>
---
 libavformat/http.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index 7bce821535..123a7c77f2 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -1853,15 +1853,13 @@ static int http_shutdown(URLContext *h, int flags)
         ((flags & AVIO_FLAG_READ) && s->chunked_post && s->listen)) {
         ret = ffurl_write(s->hd, footer, sizeof(footer) - 1);
         ret = ret > 0 ? 0 : ret;
-        /* flush the receive buffer when it is write only mode */
+
+        /* Read and parse http headers when it is write only mode to react to response errors */
         if (!(flags & AVIO_FLAG_READ)) {
-            char buf[1024];
             int read_ret;
-            s->hd->flags |= AVIO_FLAG_NONBLOCK;
-            read_ret = ffurl_read(s->hd, buf, sizeof(buf));
-            s->hd->flags &= ~AVIO_FLAG_NONBLOCK;
+            read_ret = http_read_header(h);
             if (read_ret < 0 && read_ret != AVERROR(EAGAIN)) {
-                av_log(h, AV_LOG_ERROR, "URL read error: %s\n", av_err2str(read_ret));
+                av_log(h, AV_LOG_ERROR, "HTTP error: %s\n", av_err2str(read_ret));
                 ret = read_ret;
             }
         }
-- 
2.30.2



More information about the ffmpeg-devel mailing list