[FFmpeg-devel] [PATCH] HTTP: Simplify the handling of chunked vs non-chunked posts

Ronald S. Bultje rsbultje
Mon Jun 21 20:21:49 CEST 2010


Hi,

On Mon, Jun 21, 2010 at 2:07 PM, Martin Storsj? <martin at martin.st> wrote:
> Here's a version of the same concept, using only chunksize instead of the
> is_chunked variable.
[..]
> @@ -152,7 +151,7 @@ static int http_open(URLContext *h, const char *uri, int flags)
>      }
>      h->priv_data = s;
>      s->filesize = -1;
> -    s->is_chunked = 1;
> +    s->chunksize = 0; /* Default to chunked POSTs */
>      s->off = 0;
>      s->init = 0;
>      s->hd = NULL;
> @@ -330,16 +329,14 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
>      s->line_count = 0;
>      s->off = 0;
>      s->filesize = -1;
> -    s->chunksize = -1;
>      if (post) {
> -        /* always use chunked encoding for upload data */
> -        s->chunksize = 0;
>          /* Pretend that it did work. We didn't read any header yet, since
>           * we've still to send the POST data, but the code calling this
>           * function will check http_code after we return. */
>          s->http_code = 200;
>          return 0;
>      }
> +    s->chunksize = -1;
>
>      /* wait for header */
>      for(;;) {

This breaks if the server decides to switch, the variable should be
set in connect() as is done now, not in open(). In addition, it should
be set to 0 for POST (chunked write default) and -1 for GET (in
absence of the Content-Encoding: chunked\r\n in the HTTP response,
default is non-chunked).


> @@ -434,7 +431,7 @@ static int http_write(URLContext *h, const uint8_t *buf, int size)
>          return AVERROR(EIO);
>
>      if (s->chunksize == -1) {
> -        /* headers are sent without any special encoding */
> +        /* non-chunked data is sent without any special encoding */
>          return url_write(s->hd, buf, size);
>      }

This can be applied separately.

Ronald



More information about the ffmpeg-devel mailing list