diff mbox series

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

Message ID 20200217151506.11852-1-george@nsup.org
State New
Headers show
Series [FFmpeg-devel] lavf/http: accept both GET and POST in read-write mode.
Related show

Checks

Context Check Description
andriy/ffmpeg-patchwork pending
andriy/ffmpeg-patchwork success Applied patch
andriy/ffmpeg-patchwork success Configure finished
andriy/ffmpeg-patchwork success Make finished
andriy/ffmpeg-patchwork success Make fate finished

Commit Message

Nicolas George Feb. 17, 2020, 3:15 p.m. UTC
Signed-off-by: Nicolas George <george@nsup.org>
---
 libavformat/http.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

Comments

Nicolas George Feb. 17, 2020, 7:22 p.m. UTC | #1
Nicolas George (12020-02-17):
> Signed-off-by: Nicolas George <george@nsup.org>
> ---
>  libavformat/http.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)

Disregard: the client will be in write mode even for a POST, and reading
on it will not work.

Regards,
diff mbox series

Patch

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)))