From 6149485f6c6c2e600987a2759d97c546d4cf5da0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Storsj=C3=B6?= Date: Thu, 10 Nov 2011 11:03:35 +0200 Subject: [PATCH] http: Change the chunksize AVOption into chunked_post MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The chunksize internal variable has two different uses - for reading, it's the amount of data left of the current chunk (or -1 if the server doesn't send data in chunked mode), where it's only an internal state variable. For writing, it's used to decide whether to enable chunked encoding (by default), by using the value 0, or disable chunked encoding (value -1). This, while consistent, doesn't make much sense to expose as an AVOption. This splits the usage of the internal variable into two variables, chunksize which is used for reading (as before), and chunked_post which is the user-settable option, with the values 0 and 1, where 1 is default. Signed-off-by: Martin Storsjö --- libavformat/http.c | 9 +++++---- libavformat/rtsp.c | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libavformat/http.c b/libavformat/http.c index 7cb65338cea..d5c02ddce0f 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -49,13 +49,14 @@ typedef struct { HTTPAuthState auth_state; char *headers; int willclose; /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */ + int chunked_post; } HTTPContext; #define OFFSET(x) offsetof(HTTPContext, x) #define D AV_OPT_FLAG_DECODING_PARAM #define E AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { -{"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enables it", OFFSET(chunksize), AV_OPT_TYPE_INT64, {.dbl = 0}, -1, 0, E }, /* Default to 0, for chunked POSTs */ +{"chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1, E }, {"headers", "custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E }, {NULL} }; @@ -338,7 +339,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr, "\r\n", post ? "POST" : "GET", path, - post && s->chunksize >= 0 ? "Transfer-Encoding: chunked\r\n" : "", + post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : "", headers, authstr ? authstr : ""); @@ -435,7 +436,7 @@ static int http_write(URLContext *h, const uint8_t *buf, int size) char crlf[] = "\r\n"; HTTPContext *s = h->priv_data; - if (s->chunksize == -1) { + if (!s->chunked_post) { /* non-chunked data is sent without any special encoding */ return ffurl_write(s->hd, buf, size); } @@ -461,7 +462,7 @@ static int http_close(URLContext *h) HTTPContext *s = h->priv_data; /* signal end of chunked encoding if used */ - if ((h->flags & AVIO_FLAG_WRITE) && s->chunksize != -1) { + if ((h->flags & AVIO_FLAG_WRITE) && s->chunked_post) { ret = ffurl_write(s->hd, footer, sizeof(footer) - 1); ret = ret > 0 ? 0 : ret; } diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index 862582aaa80..8f7bd3718f7 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -1486,7 +1486,7 @@ redirect: "Expires: Sun, 9 Jan 1972 00:00:00 GMT\r\n", sessioncookie); av_opt_set(rt->rtsp_hd_out->priv_data, "headers", headers, 0); - av_opt_set(rt->rtsp_hd_out->priv_data, "chunksize", "-1", 0); + av_opt_set(rt->rtsp_hd_out->priv_data, "chunked_post", "0", 0); /* Initialize the authentication state for the POST session. The HTTP * protocol implementation doesn't properly handle multi-pass -- 2.39.2