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

Martin Storsjö martin
Mon Jun 21 20:55:22 CEST 2010


On Mon, 21 Jun 2010, Ronald S. Bultje wrote:

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

No, it doesn't. It still gets set in connect(), just as it is done now, I 
just moved setting it down to below the if (post) block, so that we don't 
touch it in the POST case.

Currently, it is uninitialized before connect() has been called, but after 
this patch, it's initialized to 0 in open() and gets set to -1 for GET in 
connect(). If we want to make it even more complex, we could of course 
check the method in open() and set it to either -1 or 0, but it wouldn't 
matter since we still reset it to -1 in connect() for GET.

For the POST case, we only set it to 0 in open() and don't touch it in 
connect(), so that we can override it with another value inbetween.

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

Applied.

// Martin



More information about the ffmpeg-devel mailing list