summaryrefslogtreecommitdiff
path: root/libavformat/http.c
diff options
context:
space:
mode:
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>2012-05-28 15:03:19 +0200
committerMartin Storsjö <martin@martin.st>2012-05-28 16:42:14 +0300
commit3bdb438e6517ec342e93298de571688584050d68 (patch)
tree9b57484b487ecb9d000e4bb6c2c2020f5674d735 /libavformat/http.c
parent0426c6931070a65a7ec8362d12038ef10fa015ee (diff)
http: Add support for using persistent connections
Add a new AVOption 'multiple_requests', which indicates if we want to use persistent connections (ie. Connection: keep-alive). Signed-off-by: Martin Storsjö <martin@martin.st>
Diffstat (limited to 'libavformat/http.c')
-rw-r--r--libavformat/http.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index f978dc17af..0a81a38da1 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -53,6 +53,7 @@ typedef struct {
int chunked_post;
int end_chunked_post; /**< A flag which indicates if the end of chunked encoding has been sent. */
int end_header; /**< A flag which indicates we have finished to read POST reply. */
+ int multiple_requests; /**< A flag which indicates if we use persistent connections. */
} HTTPContext;
#define OFFSET(x) offsetof(HTTPContext, x)
@@ -61,6 +62,7 @@ typedef struct {
static const AVOption options[] = {
{"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 },
+{"multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D|E },
{NULL}
};
#define HTTP_CLASS(flavor)\
@@ -382,9 +384,17 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
if (!has_header(s->headers, "\r\nRange: ") && !post)
len += av_strlcatf(headers + len, sizeof(headers) - len,
"Range: bytes=%"PRId64"-\r\n", s->off);
- if (!has_header(s->headers, "\r\nConnection: "))
- len += av_strlcpy(headers + len, "Connection: close\r\n",
- sizeof(headers)-len);
+
+ if (!has_header(s->headers, "\r\nConnection: ")) {
+ if (s->multiple_requests) {
+ len += av_strlcpy(headers + len, "Connection: keep-alive\r\n",
+ sizeof(headers) - len);
+ } else {
+ len += av_strlcpy(headers + len, "Connection: close\r\n",
+ sizeof(headers) - len);
+ }
+ }
+
if (!has_header(s->headers, "\r\nHost: "))
len += av_strlcatf(headers + len, sizeof(headers) - len,
"Host: %s\r\n", hoststr);