[FFmpeg-devel] [PATCH] lavf/http: accept both GET and POST in read-write mode.

Nicolas George george at nsup.org
Mon Feb 17 17:15:08 EET 2020


Signed-off-by: Nicolas George <george at nsup.org>
---
 libavformat/http.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/libavformat/http.c b/libavformat/http.c
index c9415578aa..135b533203 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -903,11 +903,19 @@ static int cookie_string(AVDictionary *dict, char **cookies)
     return 0;
 }
 
+static int method_allowed(URLContext *h, const char *method)
+{
+    if (!av_strcasecmp(method, "GET") && (h->flags & AVIO_FLAG_WRITE))
+        return 1;
+    if (!av_strcasecmp(method, "POST") && (h->flags & AVIO_FLAG_READ))
+        return 1;
+    return 0;
+}
+
 static int process_line(URLContext *h, char *line, int line_count,
                         int *new_location)
 {
     HTTPContext *s = h->priv_data;
-    const char *auto_method =  h->flags & AVIO_FLAG_READ ? "POST" : "GET";
     char *tag, *p, *end, *method, *resource, *version;
     int ret;
 
@@ -934,10 +942,11 @@ static int process_line(URLContext *h, char *line, int line_count,
                 }
             } else {
                 // use autodetected HTTP method to expect
-                av_log(h, AV_LOG_TRACE, "Autodetected %s HTTP method\n", auto_method);
-                if (av_strcasecmp(auto_method, method)) {
-                    av_log(h, AV_LOG_ERROR, "Received and autodetected HTTP method did not match "
-                           "(%s autodetected %s received)\n", auto_method, method);
+                if (!method_allowed(h, method)) {
+                    const char *mode[2][2] = { { "null", "read", }, { "write", "rw" } };
+                    av_log(h, AV_LOG_ERROR, "HTTP method %s not allowed in %s mode\n",
+                           method,
+                           mode[!!(h->flags & AVIO_FLAG_WRITE)][!!(h->flags & AVIO_FLAG_READ)]);
                     return ff_http_averror(400, AVERROR(EIO));
                 }
                 if (!(s->method = av_strdup(method)))
-- 
2.25.0



More information about the ffmpeg-devel mailing list