Revision 077026cc libavformat/http.c

View differences:

libavformat/http.c
48 48
    HTTPAuthState auth_state;
49 49
    int init;
50 50
    unsigned char headers[BUFFER_SIZE];
51
    int is_chunked;
52 51
} HTTPContext;
53 52

  
54 53
static int http_connect(URLContext *h, const char *path, const char *hoststr,
......
67 66

  
68 67
void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked)
69 68
{
70
    ((HTTPContext*)h->priv_data)->is_chunked = is_chunked;
69
    ((HTTPContext*)h->priv_data)->chunksize = is_chunked ? 0 : -1;
71 70
}
72 71

  
73 72
/* return non zero if error */
......
152 151
    }
153 152
    h->priv_data = s;
154 153
    s->filesize = -1;
155
    s->is_chunked = 1;
154
    s->chunksize = 0; /* Default to chunked POSTs */
156 155
    s->off = 0;
157 156
    s->init = 0;
158 157
    s->hd = NULL;
......
316 315
             "\r\n",
317 316
             post ? "POST" : "GET",
318 317
             path,
319
             post && s->is_chunked ? "Transfer-Encoding: chunked\r\n" : "",
318
             post && s->chunksize >= 0 ? "Transfer-Encoding: chunked\r\n" : "",
320 319
             headers,
321 320
             authstr ? authstr : "");
322 321

  
......
330 329
    s->line_count = 0;
331 330
    s->off = 0;
332 331
    s->filesize = -1;
333
    s->chunksize = -1;
334 332
    if (post) {
335
        /* always use chunked encoding for upload data */
336
        s->chunksize = 0;
337 333
        /* Pretend that it did work. We didn't read any header yet, since
338 334
         * we've still to send the POST data, but the code calling this
339 335
         * function will check http_code after we return. */
340 336
        s->http_code = 200;
341 337
        return 0;
342 338
    }
339
    s->chunksize = -1;
343 340

  
344 341
    /* wait for header */
345 342
    for(;;) {
......
442 439
     * signal EOF */
443 440
    if (size > 0) {
444 441
        /* upload data using chunked encoding */
445
        if(s->is_chunked) {
446 442
            snprintf(temp, sizeof(temp), "%x\r\n", size);
447 443
            if ((ret = url_write(s->hd, temp, strlen(temp))) < 0)
448 444
                return ret;
449
        }
450 445

  
451 446
        if ((ret = url_write(s->hd, buf, size)) < 0)
452 447
            return ret;
453 448

  
454
        if (s->is_chunked && (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
449
        if ((ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
455 450
            return ret;
456 451
    }
457 452
    return size;

Also available in: Unified diff