[FFmpeg-devel] [PATCH 1/2] avformat/http: add referer option into http

Steven Liu lq at chinaffmpeg.org
Tue Jan 9 09:38:44 EET 2018


add Referer message if referer have been set.

Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
---
 doc/protocols.texi | 3 +++
 libavformat/http.c | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index 98deb73005..c24dc74505 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -296,6 +296,9 @@ Use persistent connections if set to 1, default is 0.
 @item post_data
 Set custom HTTP post data.
 
+ at item referer
+Set the Referer header. Include 'Referer: URL' header in HTTP request.
+
 @item user_agent
 Override the User-Agent header. If not specified the protocol will use a
 string describing the libavformat build. ("Lavf/<version>")
diff --git a/libavformat/http.c b/libavformat/http.c
index 4806b1e59b..86ee23de6d 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -76,6 +76,7 @@ typedef struct HTTPContext {
     char *mime_type;
     char *http_version;
     char *user_agent;
+    char *referer;
 #if FF_API_HTTP_USER_AGENT
     char *user_agent_deprecated;
 #endif
@@ -138,6 +139,7 @@ static const AVOption options[] = {
     { "headers", "set custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D | E },
     { "content_type", "set a specific content type for the POST messages", OFFSET(content_type), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D | E },
     { "user_agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT }, 0, 0, D },
+    { "referer", "override referer header", OFFSET(referer), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
 #if FF_API_HTTP_USER_AGENT
     { "user-agent", "override User-Agent header", OFFSET(user_agent_deprecated), AV_OPT_TYPE_STRING, { .str = DEFAULT_USER_AGENT }, 0, 0, D },
 #endif
@@ -1197,6 +1199,12 @@ static int http_connect(URLContext *h, const char *path, const char *local_path,
     if (!has_header(s->headers, "\r\nUser-Agent: "))
         len += av_strlcatf(headers + len, sizeof(headers) - len,
                            "User-Agent: %s\r\n", s->user_agent);
+    if (s->referer) {
+        /* set default headers if needed */
+        if (!has_header(s->headers, "\r\nReferer: "))
+            len += av_strlcatf(headers + len, sizeof(headers) - len,
+                               "Referer: %s\r\n", s->referer);
+    }
     if (!has_header(s->headers, "\r\nAccept: "))
         len += av_strlcpy(headers + len, "Accept: */*\r\n",
                           sizeof(headers) - len);
-- 
2.14.3 (Apple Git-98)





More information about the ffmpeg-devel mailing list