diff mbox

[FFmpeg-devel] avformat/http: fix chunked response w/ multiple_requests=1

Message ID 20171113203108.25467-1-ffmpeg@tmm1.net
State Accepted
Commit 91a565e20f0c220a6bc37e58c11cea4a3590149c
Headers show

Commit Message

Aman Gupta Nov. 13, 2017, 8:31 p.m. UTC
From: Aman Gupta <aman@tmm1.net>

Currently if you use the multiple_requests=1 option and try to receive a
chunked-encoded response, http_buf_read() will hang forever.

After this patch, EOF is emulated once a 0-byte final chunk is
received by setting a new flag. This flag is reset in ff_http_do_new_request(),
which is used to make additional requests on the open socket.
---
 libavformat/http.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

Comments

Ronald S. Bultje Nov. 14, 2017, 11:59 a.m. UTC | #1
Hi,

On Mon, Nov 13, 2017 at 3:31 PM, Aman Gupta <ffmpeg@tmm1.net> wrote:

> From: Aman Gupta <aman@tmm1.net>
>
> Currently if you use the multiple_requests=1 option and try to receive a
> chunked-encoded response, http_buf_read() will hang forever.
>
> After this patch, EOF is emulated once a 0-byte final chunk is
> received by setting a new flag. This flag is reset in
> ff_http_do_new_request(),
> which is used to make additional requests on the open socket.
> ---
>  libavformat/http.c | 12 +++++++++++-
>  1 file changed, 11 insertions(+), 1 deletion(-)


I think this is OK. Do you have push access or should I merge for you?

Ronald
Aman Gupta Nov. 14, 2017, 2:52 p.m. UTC | #2
On Tue, Nov 14, 2017 at 3:59 AM Ronald S. Bultje <rsbultje@gmail.com> wrote:

> Hi,
>
> On Mon, Nov 13, 2017 at 3:31 PM, Aman Gupta <ffmpeg@tmm1.net> wrote:
>
>> From: Aman Gupta <aman@tmm1.net>
>>
>> Currently if you use the multiple_requests=1 option and try to receive a
>> chunked-encoded response, http_buf_read() will hang forever.
>>
>> After this patch, EOF is emulated once a 0-byte final chunk is
>> received by setting a new flag. This flag is reset in
>> ff_http_do_new_request(),
>> which is used to make additional requests on the open socket.
>> ---
>>  libavformat/http.c | 12 +++++++++++-
>>  1 file changed, 11 insertions(+), 1 deletion(-)
>
>
> I think this is OK. Do you have push access or should I merge for you?
>

I can push it, thanks.

Aman


> Ronald
>
diff mbox

Patch

diff --git a/libavformat/http.c b/libavformat/http.c
index 29635eb546..056d5f6583 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -66,6 +66,7 @@  typedef struct HTTPContext {
     int http_code;
     /* Used if "Transfer-Encoding: chunked" otherwise -1. */
     uint64_t chunksize;
+    int chunkend;
     uint64_t off, end_off, filesize;
     char *location;
     HTTPAuthState auth_state;
@@ -305,6 +306,7 @@  int ff_http_do_new_request(URLContext *h, const char *uri)
     AVDictionary *options = NULL;
     int ret;
 
+    s->chunkend      = 0;
     s->off           = 0;
     s->icy_data_read = 0;
     av_free(s->location);
@@ -1281,6 +1283,9 @@  static int http_buf_read(URLContext *h, uint8_t *buf, int size)
     int len;
 
     if (s->chunksize != UINT64_MAX) {
+        if (s->chunkend) {
+            return AVERROR_EOF;
+        }
         if (!s->chunksize) {
             char line[32];
             int err;
@@ -1296,7 +1301,12 @@  static int http_buf_read(URLContext *h, uint8_t *buf, int size)
                    "Chunked encoding data size: %"PRIu64"\n",
                     s->chunksize);
 
-            if (!s->chunksize) {
+            if (!s->chunksize && s->multiple_requests) {
+                http_get_line(s, line, sizeof(line)); // read empty chunk
+                s->chunkend = 1;
+                return 0;
+            }
+            else if (!s->chunksize) {
                 av_log(h, AV_LOG_DEBUG, "Last chunk received, closing conn\n");
                 ffurl_closep(&s->hd);
                 return 0;