summaryrefslogtreecommitdiff
path: root/libavformat/http.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2011-11-11 02:32:38 +0100
committerMichael Niedermayer <michaelni@gmx.at>2011-11-11 02:50:35 +0100
commit6d91045d835635fe889f684bdf77f68e00b15d0b (patch)
treead30db96b3ae0e94efbb8878e0850bd2945bdaf6 /libavformat/http.c
parent554caed2d397e137286f2cc71c6bac477b41fa96 (diff)
parent299809defb05eae093cb72da97dfbbb7e17e08fe (diff)
Merge remote-tracking branch 'qatar/master'
* qatar/master: (29 commits) doc: update libavfilter documentation tls: Use the URLContext as logging context aes: Avoid illegal read and don't generate more key than we use. mpc7: Fix memset call in mpc7_decode_frame function atrac1: use correct context for av_log() apedec: consume the whole packet when copying to the decoder buffer. apedec: do not needlessly copy s->samples to nblocks. apedec: check output buffer size after calculating actual output size apedec: remove unneeded entropy decoder normalization. truespeech: use memmove() in truespeech_update_filters() vorbisdec: remove AVCODEC_MAX_AUDIO_FRAME_SIZE check vorbisdec: remove unneeded buf_size==0 check vorbisdec: return proper error codes instead of made-up ones http: Don't add a Range: bytes=0- header for POST sunrast: Check for invalid/corrupted bitstream http: Change the chunksize AVOption into chunked_post http: Add encoding/decoding flags to the AVOptions avconv: remove some codec-specific hacks crypto: add decoding flag to options. tls: use AVIO_FLAG_NONBLOCK instead of deprecated URL_FLAG_NONBLOCK ... Conflicts: doc/libavfilter.texi libavcodec/atrac1.c libavcodec/sunrast.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/http.c')
-rw-r--r--libavformat/http.c56
1 files changed, 31 insertions, 25 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index 414eb8719f..5f1837d6ad 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -47,36 +47,33 @@ typedef struct {
int64_t off, filesize;
char location[MAX_URL_SIZE];
HTTPAuthState auth_state;
- unsigned char headers[BUFFER_SIZE];
+ 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 }, /* 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}
};
-static const AVClass httpcontext_class = {
- .class_name = "HTTP",
- .item_name = av_default_item_name,
- .option = options,
- .version = LIBAVUTIL_VERSION_INT,
+#define HTTP_CLASS(flavor)\
+static const AVClass flavor ## _context_class = {\
+ .class_name = #flavor,\
+ .item_name = av_default_item_name,\
+ .option = options,\
+ .version = LIBAVUTIL_VERSION_INT,\
};
+HTTP_CLASS(http);
+HTTP_CLASS(https);
+
static int http_connect(URLContext *h, const char *path, const char *hoststr,
const char *auth, int *new_location);
-void ff_http_set_headers(URLContext *h, const char *headers)
-{
- HTTPContext *s = h->priv_data;
- int len = strlen(headers);
-
- if (len && strcmp("\r\n", headers + len - 2))
- av_log(h, AV_LOG_ERROR, "No trailing CRLF found in HTTP header.\n");
-
- av_strlcpy(s->headers, headers, sizeof(s->headers));
-}
-
void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
{
memcpy(&((HTTPContext*)dest->priv_data)->auth_state,
@@ -168,6 +165,12 @@ static int http_open(URLContext *h, const char *uri, int flags)
s->filesize = -1;
av_strlcpy(s->location, uri, sizeof(s->location));
+ if (s->headers) {
+ int len = strlen(s->headers);
+ if (len < 2 || strcmp("\r\n", s->headers + len - 2))
+ av_log(h, AV_LOG_WARNING, "No trailing CRLF found in HTTP header.\n");
+ }
+
return http_open_cnx(h);
}
static int http_getc(HTTPContext *s)
@@ -285,6 +288,8 @@ static int process_line(URLContext *h, char *line, int line_count,
static inline int has_header(const char *str, const char *header)
{
/* header + 2 to skip over CRLF prefix. (make sure you have one!) */
+ if (!str)
+ return 0;
return av_stristart(str, header + 2, NULL) || av_stristr(str, header);
}
@@ -312,7 +317,7 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
if (!has_header(s->headers, "\r\nAccept: "))
len += av_strlcpy(headers + len, "Accept: */*\r\n",
sizeof(headers) - len);
- if (!has_header(s->headers, "\r\nRange: "))
+ 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: "))
@@ -323,7 +328,8 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
"Host: %s\r\n", hoststr);
/* now add in custom headers */
- av_strlcpy(headers+len, s->headers, sizeof(headers)-len);
+ if (s->headers)
+ av_strlcpy(headers + len, s->headers, sizeof(headers) - len);
snprintf(s->buffer, sizeof(s->buffer),
"%s %s HTTP/1.1\r\n"
@@ -333,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 : "");
@@ -430,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);
}
@@ -456,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;
}
@@ -519,7 +525,7 @@ URLProtocol ff_http_protocol = {
.url_close = http_close,
.url_get_file_handle = http_get_file_handle,
.priv_data_size = sizeof(HTTPContext),
- .priv_data_class = &httpcontext_class,
+ .priv_data_class = &http_context_class,
};
#endif
#if CONFIG_HTTPS_PROTOCOL
@@ -532,6 +538,6 @@ URLProtocol ff_https_protocol = {
.url_close = http_close,
.url_get_file_handle = http_get_file_handle,
.priv_data_size = sizeof(HTTPContext),
- .priv_data_class = &httpcontext_class,
+ .priv_data_class = &https_context_class,
};
#endif