r9630 jmb - in /branches/jmb/new-cache: amiga/fetch_file.c beos/beos_fetch_rsrc.cpp content/fetchers/fetch_curl.c content/fetchers/fetch_data.c

netsurf at semichrome.net netsurf at semichrome.net
Tue Oct 13 00:14:27 BST 2009


Author: jmb
Date: Mon Oct 12 18:14:20 2009
New Revision: 9630

URL: http://source.netsurf-browser.org?rev=9630&view=rev
Log:
Stop issuing FETCH_TYPE messages.
Instead, make non-HTTP handlers emit Content-Type/Content-Length headers through FETCH_HEADER.
The low-level cache is responsible for making sense of all of this stuff, rather than the fetch protocol handlers.

Modified:
    branches/jmb/new-cache/amiga/fetch_file.c
    branches/jmb/new-cache/beos/beos_fetch_rsrc.cpp
    branches/jmb/new-cache/content/fetchers/fetch_curl.c
    branches/jmb/new-cache/content/fetchers/fetch_data.c

Modified: branches/jmb/new-cache/amiga/fetch_file.c
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/amiga/fetch_file.c?rev=9630&r1=9629&r2=9630&view=diff
==============================================================================
--- branches/jmb/new-cache/amiga/fetch_file.c (original)
+++ branches/jmb/new-cache/amiga/fetch_file.c Mon Oct 12 18:14:20 2009
@@ -272,6 +272,7 @@
 
 				if(fetch->fh)
 				{
+					char header[64];
 					struct ExamineData *fib;
 					if(fib = ExamineObjectTags(EX_FileHandleInput,fetch->fh,TAG_DONE))
 					{
@@ -283,8 +284,18 @@
 					fetch->mimetype = fetch_mimetype(fetch->path);
 					LOG(("mimetype %s len %ld",fetch->mimetype,fetch->len));
 
-					ami_fetch_file_send_callback(FETCH_TYPE,
-						fetch, fetch->mimetype, (ULONG)fetch->len);
+					snprintf(header, sizeof header,
+							"Content-Type: %s",
+							fetch->mimetype);
+					ami_fetch_file_send_callback(FETCH_HEADER,
+						fetch, header, strlen(header));
+
+					snprintf(header, sizeof header,
+							"Content-Length: %ld",
+							fetch->len);
+					ami_fetch_file_send_callback(FETCH_HEADER,
+						fetch, header, strlen(header));
+
 				}
 				else
 				{

Modified: branches/jmb/new-cache/beos/beos_fetch_rsrc.cpp
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/beos/beos_fetch_rsrc.cpp?rev=9630&r1=9629&r2=9630&view=diff
==============================================================================
--- branches/jmb/new-cache/beos/beos_fetch_rsrc.cpp (original)
+++ branches/jmb/new-cache/beos/beos_fetch_rsrc.cpp Mon Oct 12 18:14:20 2009
@@ -277,6 +277,8 @@
 
 		/* Only process non-aborted fetches */
 		if (!c->aborted && fetch_rsrc_process(c) == true) {
+			char header[64];
+
 			fetch_set_http_code(c->parent_fetch, 200);
 			LOG(("setting rsrc: MIME type to %s, length to %zd",
 					c->mimetype, c->datalen));
@@ -284,8 +286,16 @@
 			 * Therefore, we _must_ check for this after _every_
 			 * call to fetch_rsrc_send_callback().
 			 */
-			fetch_rsrc_send_callback(FETCH_TYPE,
-				c, c->mimetype, c->datalen);
+			snprintf(header, sizeof header, "Content-Type: %s",
+					c->mimetype);
+			fetch_rsrc_send_callback(FETCH_HEADER, c, header,
+					strlen(header));
+
+			snprintf(header, sizeof header, "Content-Length: %zd",
+					c->datalen);
+			fetch_rsrc_send_callback(FETCH_HEADER, c, header,
+					strlen(header));
+
 			if (!c->aborted) {
 				fetch_rsrc_send_callback(FETCH_DATA, 
 					c, c->data, c->datalen);

Modified: branches/jmb/new-cache/content/fetchers/fetch_curl.c
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/content/fetchers/fetch_curl.c?rev=9630&r1=9629&r2=9630&view=diff
==============================================================================
--- branches/jmb/new-cache/content/fetchers/fetch_curl.c (original)
+++ branches/jmb/new-cache/content/fetchers/fetch_curl.c Mon Oct 12 18:14:20 2009
@@ -1081,10 +1081,7 @@
 bool fetch_curl_process_headers(struct curl_fetch_info *f)
 {
 	long http_code;
-	const char *type;
 	CURLcode code;
-	struct stat s;
-	char *url_path = 0;
 
 	f->had_headers = true;
 
@@ -1107,13 +1104,14 @@
 	/* handle HTTP redirects (3xx response codes) */
 	if (300 <= http_code && http_code < 400 && f->location != 0) {
 		LOG(("FETCH_REDIRECT, '%s'", f->location));
-		fetch_send_callback(FETCH_REDIRECT, f->fetch_handle, f->location, 0);
+		fetch_send_callback(FETCH_REDIRECT, f->fetch_handle, 
+				f->location, 0);
 		return true;
 	}
 
 	/* handle HTTP 401 (Authentication errors) */
 	if (http_code == 401) {
-		fetch_send_callback(FETCH_AUTH, f->fetch_handle, f->realm,0);
+		fetch_send_callback(FETCH_AUTH, f->fetch_handle, f->realm, 0);
 		return true;
 	}
 
@@ -1125,49 +1123,58 @@
 		return true;
 	}
 
-	/* find MIME type from headers or filetype for local files */
-	code = curl_easy_getinfo(f->curl_handle, CURLINFO_CONTENT_TYPE, &type);
-	assert(code == CURLE_OK);
-
-	if (strncmp(f->url, "file:///", 8) == 0)
-		url_path = curl_unescape(f->url + 7,
-				(int) strlen(f->url) - 7);
-
-	if (url_path && stat(url_path, &s) == 0) {
-		/* file: URL and file exists */
-		/* create etag */
-		char etag_buf[20];
-		snprintf(etag_buf, sizeof etag_buf,
-				"ETag: \"%10d\"", (int) s.st_mtime);
-		/* And send it to the header handler */
-		fetch_send_callback(FETCH_HEADER, f->fetch_handle, etag_buf,
-				strlen(etag_buf));
-
-		/* don't set last modified time so as to ensure that local
-		 * files are revalidated at all times. */
-
-		/* If performed a conditional request and unmodified ... */
-		if (f->last_modified && f->file_etag &&
-				f->last_modified > s.st_mtime &&
-				f->file_etag == s.st_mtime) {
-			fetch_send_callback(FETCH_NOTMODIFIED, f->fetch_handle,
-					    0, 0);
+	/* find MIME type from filetype for local files */
+	if (strncmp(f->url, "file:///", 8) == 0) {
+		struct stat s;
+		char *url_path = curl_unescape(f->url + 7, 
+				(int) strlen(f->url + 7));
+
+		if (url_path != NULL && stat(url_path, &s) == 0) {
+			/* file: URL and file exists */
+			char header[64];
+			const char *type;
+
+			/* create etag */
+			snprintf(header, sizeof header,
+					"ETag: \"%10d\"", (int) s.st_mtime);
+			/* And send it to the header handler */
+			fetch_send_callback(FETCH_HEADER, f->fetch_handle, 
+					header, strlen(header));
+
+			/* create Content-Type */
+			type = fetch_filetype(url_path);
+			snprintf(header, sizeof header,	
+					"Content-Type: %s", type);
+			/* Send it to the header handler */
+			fetch_send_callback(FETCH_HEADER, f->fetch_handle,
+					header, strlen(header));
+
+			/* create Content-Length */
+			type = fetch_filetype(url_path);
+			snprintf(header, sizeof header,	
+					"Content-Length: %ld", s.st_size);
+			/* Send it to the header handler */
+			fetch_send_callback(FETCH_HEADER, f->fetch_handle,
+					header, strlen(header));
+
+			/* don't set last modified time so as to ensure that 
+			 * local files are revalidated at all times. */
+
+			/* Report not modified, if appropriate */
+			if (f->last_modified && f->file_etag &&
+					f->last_modified > s.st_mtime &&
+					f->file_etag == s.st_mtime) {
+				fetch_send_callback(FETCH_NOTMODIFIED, 
+						f->fetch_handle, 0, 0);
+				curl_free(url_path);
+				return true;
+			}
+		}
+
+		if (url_path != NULL)
 			curl_free(url_path);
-			return true;
-		}
-	}
-
-	if (type == 0) {
-		type = "text/plain";
-		if (url_path) {
-			type = fetch_filetype(url_path);
-		}
-	}
-
-	curl_free(url_path);
-
-	LOG(("FETCH_TYPE, '%s'", type));
-	fetch_send_callback(FETCH_TYPE, f->fetch_handle, type, f->content_length);
+	}
+
 	if (f->abort)
 		return true;
 

Modified: branches/jmb/new-cache/content/fetchers/fetch_data.c
URL: http://source.netsurf-browser.org/branches/jmb/new-cache/content/fetchers/fetch_data.c?rev=9630&r1=9629&r2=9630&view=diff
==============================================================================
--- branches/jmb/new-cache/content/fetchers/fetch_data.c (original)
+++ branches/jmb/new-cache/content/fetchers/fetch_data.c Mon Oct 12 18:14:20 2009
@@ -263,6 +263,8 @@
 
 		/* Only process non-aborted fetches */
 		if (!c->aborted && fetch_data_process(c) == true) {
+			char header[64];
+
 			fetch_set_http_code(c->parent_fetch, 200);
 			LOG(("setting data: MIME type to %s, length to %zd",
 					c->mimetype, c->datalen));
@@ -270,8 +272,16 @@
 			 * Therefore, we _must_ check for this after _every_
 			 * call to fetch_data_send_callback().
 			 */
-			fetch_data_send_callback(FETCH_TYPE,
-				c, c->mimetype, c->datalen);
+			snprintf(header, sizeof header, "Content-Type: %s",
+					c->mimetype);
+			fetch_data_send_callback(FETCH_HEADER, c, header, 
+					strlen(header));
+
+			snprintf(header, sizeof header, "Content-Length: %zd",
+					c->datalen);
+			fetch_data_send_callback(FETCH_HEADER, c, header, 
+					strlen(header));
+
 			if (!c->aborted) {
 				fetch_data_send_callback(FETCH_DATA, 
 					c, c->data, c->datalen);




More information about the netsurf-commits mailing list