changeset 6352:3472338a5e13 libavformat

http: Return EOF at the end of the content even if the connection isn't closed We do request Connection: close, but some servers ignore it.
author mstorsjo
date Mon, 09 Aug 2010 08:14:48 +0000
parents 05a6d7c6813e
children 3f938b3a355a
files http.c
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/http.c	Sat Aug 07 21:30:34 2010 +0000
+++ b/http.c	Mon Aug 09 08:14:48 2010 +0000
@@ -49,6 +49,7 @@
     char location[URL_SIZE];
     HTTPAuthState auth_state;
     unsigned char headers[BUFFER_SIZE];
+    int willclose;          /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */
 } HTTPContext;
 
 #define OFFSET(x) offsetof(HTTPContext, x)
@@ -267,6 +268,9 @@
             ff_http_auth_handle_header(&s->auth_state, tag, p);
         } else if (!strcmp (tag, "Authentication-Info")) {
             ff_http_auth_handle_header(&s->auth_state, tag, p);
+        } else if (!strcmp (tag, "Connection")) {
+            if (!strcmp(p, "close"))
+                s->willclose = 1;
         }
     }
     return 1;
@@ -337,6 +341,7 @@
     s->line_count = 0;
     s->off = 0;
     s->filesize = -1;
+    s->willclose = 0;
     if (post) {
         /* Pretend that it did work. We didn't read any header yet, since
          * we've still to send the POST data, but the code calling this
@@ -399,6 +404,8 @@
         memcpy(buf, s->buf_ptr, len);
         s->buf_ptr += len;
     } else {
+        if (!s->willclose && s->filesize >= 0 && s->off >= s->filesize)
+            return AVERROR_EOF;
         len = url_read(s->hd, buf, size);
     }
     if (len > 0) {