[FFmpeg-cvslog] avformat/http: export http_version from response

Aman Gupta git at videolan.org
Wed Dec 27 00:58:18 EET 2017


ffmpeg | branch: master | Aman Gupta <aman at tmm1.net> | Mon Dec 25 20:21:15 2017 -0800| [039007c928b4207b8bdde31c80c57dc7b917dd2f] | committer: Aman Gupta

avformat/http: export http_version from response

Can be used by the api user to figure out what http features the server supports based on the response received.

Signed-off-by: Aman Gupta <aman at tmm1.net>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=039007c928b4207b8bdde31c80c57dc7b917dd2f
---

 doc/protocols.texi | 3 +++
 libavformat/http.c | 8 ++++++++
 2 files changed, 11 insertions(+)

diff --git a/doc/protocols.texi b/doc/protocols.texi
index ca2f9ad63d..1ededa81c8 100644
--- a/doc/protocols.texi
+++ b/doc/protocols.texi
@@ -321,6 +321,9 @@ Sets the maximum delay in seconds after which to give up reconnecting
 @item mime_type
 Export the MIME type.
 
+ at item http_version
+Exports the HTTP response version number. Usually "1.0" or "1.1".
+
 @item icy
 If set to 1 request ICY (SHOUTcast) metadata from the server. If the server
 supports this, the metadata has to be retrieved by the application by reading
diff --git a/libavformat/http.c b/libavformat/http.c
index 213b6bb245..a376f1a488 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -74,6 +74,7 @@ typedef struct HTTPContext {
     char *http_proxy;
     char *headers;
     char *mime_type;
+    char *http_version;
     char *user_agent;
 #if FF_API_HTTP_USER_AGENT
     char *user_agent_deprecated;
@@ -144,6 +145,7 @@ static const AVOption options[] = {
     { "multiple_requests", "use persistent connections", OFFSET(multiple_requests), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, D | E },
     { "post_data", "set custom HTTP post data", OFFSET(post_data), AV_OPT_TYPE_BINARY, .flags = D | E },
     { "mime_type", "export the MIME type", OFFSET(mime_type), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
+    { "http_version", "export the http response version", OFFSET(http_version), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_EXPORT | AV_OPT_FLAG_READONLY },
     { "cookies", "set cookies to be sent in applicable future requests, use newline delimited Set-Cookie HTTP field value syntax", OFFSET(cookies), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, D },
     { "icy", "request ICY metadata", OFFSET(icy), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, D },
     { "icy_metadata_headers", "return ICY metadata headers", OFFSET(icy_metadata_headers), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_EXPORT },
@@ -919,6 +921,12 @@ static int process_line(URLContext *h, char *line, int line_count,
         } else {
             if (av_strncasecmp(p, "HTTP/1.0", 8) == 0)
                 s->willclose = 1;
+            while (*p != '/' && *p != '\0')
+                p++;
+            while (*p == '/')
+                p++;
+            av_freep(&s->http_version);
+            s->http_version = av_strndup(p, 3);
             while (!av_isspace(*p) && *p != '\0')
                 p++;
             while (av_isspace(*p))



More information about the ffmpeg-cvslog mailing list