[FFmpeg-devel] [PATCH] lavf/http: Export headers as AVDictionary

Stephan Holljes klaxa1337 at googlemail.com
Thu Aug 20 19:33:02 CEST 2015


Signed-off-by: Stephan Holljes <klaxa1337 at googlemail.com>
---
 libavformat/http.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/libavformat/http.c b/libavformat/http.c
index 3fd0496..2c51491 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -48,6 +48,7 @@
 #define MAX_REDIRECTS 8
 #define HTTP_SINGLE   1
 #define HTTP_MUTLI    2
+#define MAX_HEADER_LINES 100
 typedef enum {
     LOWER_PROTO,
     READ_HEADERS,
@@ -69,6 +70,8 @@ typedef struct HTTPContext {
     HTTPAuthState auth_state;
     HTTPAuthState proxy_auth_state;
     char *headers;
+    AVDictionary *headers_dict;
+    int nb_headers;
     char *mime_type;
     char *user_agent;
     char *content_type;
@@ -130,6 +133,7 @@ static const AVOption options[] = {
     { "chunked_post", "use(s) chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, { .i64 = 1 }, 0, 1, D | E },
     { "skip_read_header", "skip lower protocol initialization and reading HTTP headers.", OFFSET(skip_read_header), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, E },
     { "headers", "set custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D | E },
+    { "headers_dict", "Contains the parsed headers as a dictionary.", OFFSET(headers_dict), AV_OPT_TYPE_DICT, { 0 }, 0, 0, AV_OPT_FLAG_EXPORT | D | E },
     { "content_type", "set a specific content type for the POST messages", OFFSET(content_type), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D | E },
     { "body", "set the body of a simple HTTP reply", OFFSET(body), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, E },
     { "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT }, 0, 0, D },
@@ -922,6 +926,10 @@ static int process_line(URLContext *h, char *line, int line_count,
                 return AVERROR(ENOMEM);
         }
     }
+    if (s->nb_headers < MAX_HEADER_LINES) {
+        av_dict_set(&s->headers_dict, tag, p, 0);
+        s->nb_headers++;
+    }
     return 1;
 }
 
@@ -1044,6 +1052,7 @@ static int http_read_header(URLContext *h, int *new_location)
     int err = 0;
 
     s->chunksize = -1;
+    s->nb_headers = 0;
 
     for (;;) {
         if ((err = http_get_line(s, line, sizeof(line))) < 0)
-- 
2.1.0



More information about the ffmpeg-devel mailing list