[FFmpeg-cvslog] r23531 - in trunk/libavformat: http.c http.h

mstorsjo subversion
Tue Jun 8 13:48:03 CEST 2010


Author: mstorsjo
Date: Tue Jun  8 13:48:03 2010
New Revision: 23531

Log:
Add support for disabling chunked transfer encoding for the http protocol

Patch by Josh Allmann, josh dot allmann at gmail

Modified:
   trunk/libavformat/http.c
   trunk/libavformat/http.h

Modified: trunk/libavformat/http.c
==============================================================================
--- trunk/libavformat/http.c	Tue Jun  8 13:42:21 2010	(r23530)
+++ trunk/libavformat/http.c	Tue Jun  8 13:48:03 2010	(r23531)
@@ -48,6 +48,7 @@ typedef struct {
     HTTPAuthState auth_state;
     int init;
     unsigned char headers[BUFFER_SIZE];
+    int is_chunked;
 } HTTPContext;
 
 static int http_connect(URLContext *h, const char *path, const char *hoststr,
@@ -65,6 +66,11 @@ void ff_http_set_headers(URLContext *h, 
     av_strlcpy(s->headers, headers, sizeof(s->headers));
 }
 
+void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked)
+{
+    ((HTTPContext*)h->priv_data)->is_chunked = is_chunked;
+}
+
 /* return non zero if error */
 static int http_open_cnx(URLContext *h)
 {
@@ -148,6 +154,7 @@ static int http_open(URLContext *h, cons
     h->priv_data = s;
     s->filesize = -1;
     s->chunksize = -1;
+    s->is_chunked = 1;
     s->off = 0;
     s->init = 0;
     s->hd = NULL;
@@ -311,7 +318,7 @@ static int http_connect(URLContext *h, c
              "\r\n",
              post ? "POST" : "GET",
              path,
-             post ? "Transfer-Encoding: chunked\r\n" : "",
+             post && s->is_chunked ? "Transfer-Encoding: chunked\r\n" : "",
              headers,
              authstr ? authstr : "");
 
@@ -412,7 +419,7 @@ static int http_read(URLContext *h, uint
 /* used only when posting data */
 static int http_write(URLContext *h, const uint8_t *buf, int size)
 {
-    char temp[11];  /* 32-bit hex + CRLF + nul */
+    char temp[11] = "";  /* 32-bit hex + CRLF + nul */
     int ret;
     char crlf[] = "\r\n";
     HTTPContext *s = h->priv_data;
@@ -432,11 +439,16 @@ static int http_write(URLContext *h, con
      * signal EOF */
     if (size > 0) {
         /* upload data using chunked encoding */
+        if(s->is_chunked) {
         snprintf(temp, sizeof(temp), "%x\r\n", size);
+            if ((ret = url_write(s->hd, temp, strlen(temp))) < 0)
+                return ret;
+        }
 
-        if ((ret = url_write(s->hd, temp, strlen(temp))) < 0 ||
-            (ret = url_write(s->hd, buf, size)) < 0 ||
-            (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
+        if ((ret = url_write(s->hd, buf, size)) < 0)
+            return ret;
+
+        if (s->is_chunked && (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0)
             return ret;
     }
     return size;

Modified: trunk/libavformat/http.h
==============================================================================
--- trunk/libavformat/http.h	Tue Jun  8 13:42:21 2010	(r23530)
+++ trunk/libavformat/http.h	Tue Jun  8 13:48:03 2010	(r23531)
@@ -39,4 +39,12 @@
  */
 void ff_http_set_headers(URLContext *h, const char *headers);
 
+/**
+ * Enables or disables chunked transfer encoding. (default is enabled)
+ *
+ * @param h URL context for this HTTP connection
+ * @param is_chunked 0 to disable chunking, nonzero otherwise.
+ */
+void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked);
+
 #endif /* AVFORMAT_HTTP_H */



More information about the ffmpeg-cvslog mailing list