diff --git a/libavformat/http.c b/libavformat/http.c
index f76e995..f4ddcae 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -46,12 +46,18 @@ typedef struct {
     int64_t off, filesize;
     char location[URL_SIZE];
     HTTPAuthState auth_state;
+    unsigned char headers[BUFFER_SIZE];
 } HTTPContext;
 
 static int http_connect(URLContext *h, const char *path, const char *hoststr,
                         const char *auth, int *new_location);
 static int http_write(URLContext *h, uint8_t *buf, int size);
 
+void ff_http_set_headers(URLContext *h, const char *headers)
+{
+    HTTPContext *s = h->priv_data;
+    snprintf(s->headers, sizeof(s->headers), "%s", headers);
+}
 
 /* return non zero if error */
 int ff_http_connect(URLContext *h)
@@ -135,6 +141,7 @@ int ff_http_init(URLContext *h, const char *uri, int flags)
     s->filesize = -1;
     s->chunksize = -1;
     s->off = 0;
+    *s->headers = '\0';
     memset(&s->auth_state, 0, sizeof(s->auth_state));
     av_strlcpy(s->location, uri, URL_SIZE);
 
@@ -272,8 +279,9 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
     post = h->flags & URL_WRONLY;
     authstr = ff_http_auth_create_response(&s->auth_state, auth, path,
                                         post ? "POST" : "GET");
-    snprintf(s->buffer, sizeof(s->buffer),
-             "%s %s HTTP/1.1\r\n"
+    if(!strlen(s->headers))
+    {
+    snprintf(s->headers, sizeof(s->headers),
              "User-Agent: %s\r\n"
              "Accept: */*\r\n"
              "Range: bytes=%"PRId64"-\r\n"
@@ -282,13 +290,20 @@ static int http_connect(URLContext *h, const char *path, const char *hoststr,
              "Connection: close\r\n"
              "%s"
              "\r\n",
-             post ? "POST" : "GET",
-             path,
              LIBAVFORMAT_IDENT,
              s->off,
              hoststr,
              authstr ? authstr : "",
              post ? "Transfer-Encoding: chunked\r\n" : "");
+    }
+
+    snprintf(s->buffer, sizeof(s->buffer),
+             "%s %s HTTP/1.1\r\n"
+             "%s"
+             "\r\n",
+             post ? "POST" : "GET",
+             path,
+             s->headers);
 
     av_freep(&authstr);
     if (http_write(h, s->buffer, strlen(s->buffer)) < 0)
diff --git a/libavformat/http.h b/libavformat/http.h
index 25ae18b..1e78ec7 100644
--- a/libavformat/http.h
+++ b/libavformat/http.h
@@ -41,4 +41,12 @@ int ff_http_init(URLContext *h, const char *uri, int flags);
  */
 int ff_http_connect(URLContext *h);
 
+/**
+ * Sets custom HTTP headers. Note this overwrites all the default options.
+ *
+ * @param h URL context for this HTTP connection
+ * @param headers New headers to use for future requests.
+ */
+void ff_http_set_headers(URLContext *h, const char *headers);
+
 #endif
