From patchwork Mon Feb 17 15:15:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas George X-Patchwork-Id: 17823 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 1D6EE4483B9 for ; Mon, 17 Feb 2020 17:16:23 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ECA36689BD5; Mon, 17 Feb 2020 17:16:22 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from nef.ens.fr (nef2.ens.fr [129.199.96.40]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 293E46880E7 for ; Mon, 17 Feb 2020 17:16:16 +0200 (EET) X-ENS-nef-client: 129.199.129.80 Received: from phare.normalesup.org (phare.normalesup.org [129.199.129.80]) by nef.ens.fr (8.14.4/1.01.28121999) with ESMTP id 01HFGFrc026278 for ; Mon, 17 Feb 2020 16:16:15 +0100 Received: by phare.normalesup.org (Postfix, from userid 1001) id 1AF1AEB5D1; Mon, 17 Feb 2020 16:16:15 +0100 (CET) From: Nicolas George To: ffmpeg-devel@ffmpeg.org Date: Mon, 17 Feb 2020 16:15:08 +0100 Message-Id: <20200217151506.11852-1-george@nsup.org> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.4.3 (nef.ens.fr [129.199.96.32]); Mon, 17 Feb 2020 16:16:15 +0100 (CET) Subject: [FFmpeg-devel] [PATCH] lavf/http: accept both GET and POST in read-write mode. X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Nicolas George --- 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)))