r10912 jmb - /trunk/netsurf/content/llcache.c

netsurf at semichrome.net netsurf at semichrome.net
Wed Oct 27 23:12:00 BST 2010


Author: jmb
Date: Wed Oct 27 17:12:00 2010
New Revision: 10912

URL: http://source.netsurf-browser.org?rev=10912&view=rev
Log:
Fix bug 3096811: discard HTTP headers for all but the last response

Modified:
    trunk/netsurf/content/llcache.c

Modified: trunk/netsurf/content/llcache.c
URL: http://source.netsurf-browser.org/trunk/netsurf/content/llcache.c?rev=10912&r1=10911&r2=10912&view=diff
==============================================================================
--- trunk/netsurf/content/llcache.c (original)
+++ trunk/netsurf/content/llcache.c Wed Oct 27 17:12:00 2010
@@ -210,6 +210,18 @@
 static nserror llcache_fetch_cert_error(llcache_object *object,
 		const struct ssl_cert_info *certs, size_t num);
 
+/* Destroy headers */
+static inline void llcache_destroy_headers(llcache_object *object)
+{
+	while (object->num_headers > 0) {
+		object->num_headers--;
+
+		free(object->headers[object->num_headers].name);
+		free(object->headers[object->num_headers].value);
+	}
+	free(object->headers);
+	object->headers = NULL;
+}
 
 /* Invalidate cache control data */
 static inline void llcache_invalidate_cache_control_data(llcache_object *object)
@@ -2163,6 +2175,28 @@
 	if (error != NSERROR_OK)
 		return error;
 
+	/* The headers for multiple HTTP responses may be delivered to us if
+	 * the fetch layer receives a 401 response for which it has 
+	 * authentication credentials. This will result in a silent re-request
+	 * after which we'll receive the actual response headers for the
+	 * object we want to fetch (assuming that the credentials were correct
+	 * of course)
+	 *
+	 * Therefore, if the header is an HTTP response start marker, then we 
+	 * must discard any headers we've read so far, reset the cache data 
+	 * that we might have computed, and start again.
+	 */
+	if (strncmp(name, "HTTP/", SLEN("HTTP/")) == 0 && value[0] == '\0') {
+		time_t req_time = object->cache.req_time;
+
+		llcache_invalidate_cache_control_data(object);
+
+		/* Restore request time, so we compute object's age correctly */
+		object->cache.req_time = req_time;
+
+		llcache_destroy_headers(object);
+	}
+
 	/* Append header data to the object's headers array */
 	temp = realloc(object->headers, (object->num_headers + 1) * 
 			sizeof(llcache_header));
@@ -2231,14 +2265,7 @@
 	llcache_invalidate_cache_control_data(object);
 
 	/* Destroy headers */
-	while (object->num_headers > 0) {
-		object->num_headers--;
-
-		free(object->headers[object->num_headers].name);
-		free(object->headers[object->num_headers].value);
-	}
-	free(object->headers);
-	object->headers = NULL;
+	llcache_destroy_headers(object);
 
 	/* If there was no realm, then default to the URL */
 	/** \todo If there was no WWW-Authenticate header, use response body */




More information about the netsurf-commits mailing list