Revision f2b9b19f

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;
51 52
} HTTPContext;
52 53

  
53 54
static int http_connect(URLContext *h, const char *path, const char *hoststr,
......
65 66
    av_strlcpy(s->headers, headers, sizeof(s->headers));
66 67
}
67 68

  
69
void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked)
70
{
71
    ((HTTPContext*)h->priv_data)->is_chunked = is_chunked;
72
}
73

  
68 74
/* return non zero if error */
69 75
static int http_open_cnx(URLContext *h)
70 76
{
......
148 154
    h->priv_data = s;
149 155
    s->filesize = -1;
150 156
    s->chunksize = -1;
157
    s->is_chunked = 1;
151 158
    s->off = 0;
152 159
    s->init = 0;
153 160
    s->hd = NULL;
......
311 318
             "\r\n",
312 319
             post ? "POST" : "GET",
313 320
             path,
314
             post ? "Transfer-Encoding: chunked\r\n" : "",
321
             post && s->is_chunked ? "Transfer-Encoding: chunked\r\n" : "",
315 322
             headers,
316 323
             authstr ? authstr : "");
317 324

  
......
412 419
/* used only when posting data */
413 420
static int http_write(URLContext *h, const uint8_t *buf, int size)
414 421
{
415
    char temp[11];  /* 32-bit hex + CRLF + nul */
422
    char temp[11] = "";  /* 32-bit hex + CRLF + nul */
416 423
    int ret;
417 424
    char crlf[] = "\r\n";
418 425
    HTTPContext *s = h->priv_data;
......
432 439
     * signal EOF */
433 440
    if (size > 0) {
434 441
        /* upload data using chunked encoding */
442
        if(s->is_chunked) {
435 443
        snprintf(temp, sizeof(temp), "%x\r\n", size);
444
            if ((ret = url_write(s->hd, temp, strlen(temp))) < 0)
445
                return ret;
446
        }
447

  
448
        if ((ret = url_write(s->hd, buf, size)) < 0)
449
            return ret;
436 450

  
437
        if ((ret = url_write(s->hd, temp, strlen(temp))) < 0 ||
438
            (ret = url_write(s->hd, buf, size)) < 0 ||
439
            (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
451
        if (s->is_chunked && (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
440 452
            return ret;
441 453
    }
442 454
    return size;
libavformat/http.h
39 39
 */
40 40
void ff_http_set_headers(URLContext *h, const char *headers);
41 41

  
42
/**
43
 * Enables or disables chunked transfer encoding. (default is enabled)
44
 *
45
 * @param h URL context for this HTTP connection
46
 * @param is_chunked 0 to disable chunking, nonzero otherwise.
47
 */
48
void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked);
49

  
42 50
#endif /* AVFORMAT_HTTP_H */

Also available in: Unified diff