[vlc-devel] [PATCH 5/5] access/http: Send only one Cookie header

Antti Ajanki antti.ajanki at iki.fi
Tue Jul 22 12:09:06 CEST 2014


This is a MUST according to RFC 6265.
---
 modules/access/http.c |   31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/modules/access/http.c b/modules/access/http.c
index bdfb95a..f865e87 100644
--- a/modules/access/http.c
+++ b/modules/access/http.c
@@ -213,7 +213,11 @@ static int Connect( access_t *, uint64_t );
 static int Request( access_t *p_access, uint64_t i_tell );
 static void Disconnect( access_t * );
 
-/* Small Cookie utilities. Cookies support is partial. */
+/* Small Cookie utilities.
+ *
+ * Unimplemented features: Expires, max-age, persisting between HTTP sessions,
+ * "public suffix" domain checks (see cookie_domain_is_public_suffix).
+ */
 static http_cookie_t * cookie_parse( const char * cookie_header, const vlc_url_t *url );
 static void cookie_destroy( http_cookie_t * cookie );
 static char * cookie_get_content( const char * cookie );
@@ -1208,16 +1212,35 @@ static int Request( access_t *p_access, uint64_t i_tell )
     if( p_sys->cookies )
     {
         int i;
+        char *cookiebuf = NULL;
+
         for( i = 0; i < vlc_array_count( p_sys->cookies ); i++ )
         {
             const http_cookie_t * cookie = vlc_array_item_at_index( p_sys->cookies, i );
             if( cookie_should_be_sent( cookie, &p_sys->url) )
             {
-                msg_Dbg( p_access, "Sending Cookie %s=%s", cookie->psz_name, cookie->psz_value );
-                if( net_Printf( p_access, p_sys->fd, pvs, "Cookie: %s=%s\r\n", cookie->psz_name, cookie->psz_value ) < 0 )
-                    msg_Err( p_access, "failed to send Cookie" );
+                char *updated_buf = NULL;
+                if (asprintf(&updated_buf, "%s%s%s=%s",
+                             cookiebuf ? cookiebuf : "",
+                             cookiebuf ? "; " : "",
+                             cookie->psz_name,
+                             cookie->psz_value) == -1)
+                {
+                    msg_Err( p_access, "Failed to append a cookie" );
+                    continue;
+                }
+                if ( cookiebuf ) free( cookiebuf );
+                cookiebuf = updated_buf;
             }
         }
+
+        if (cookiebuf)
+        {
+            msg_Dbg( p_access, "Sending Cookie %s", cookiebuf );
+            if( net_Printf( p_access, p_sys->fd, pvs, "Cookie: %s\r\n", cookiebuf ) < 0 )
+                msg_Err( p_access, "failed to send Cookie" );
+            free( cookiebuf );
+        }
     }
 
     /* Authentication */
-- 
1.7.10.4




More information about the vlc-devel mailing list