diff mbox series

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

Message ID DB9P191MB1482170477EBAE21BA77A642FE1E9@DB9P191MB1482.EURP191.PROD.OUTLOOK.COM
State New
Headers show
Series [FFmpeg-devel,1/2] libavformat/http: Use http_read_header in http_shutdown to react to response errors | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

Basel Sayeh Dec. 11, 2022, 1:09 a.m. UTC
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@hotmail.com>
---
 libavformat/http.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
diff mbox series

Patch

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;
             }
         }