Hi Karry,

sorry for the late response. There is indeed a weird combination of
things at work here which I finally had the patience to track down
(hopefully). Attached patch prevents downloads from being triggered if
the HTTP status isn't 200. I am, however, unsure whether this could
have any unwanted side-effects. Testing across other websites would
therefore be appreciated!

Hannes
diff --git a/main.c b/main.c
index d70f88a..cf64c67 100644
--- a/main.c
+++ b/main.c
@@ -122,6 +122,7 @@ static void mop_up(void);
 
 /* variables */
 static char **args;
+static guint http_status;
 
 #include "config.h"
 #include "keymap.h"
@@ -133,7 +134,7 @@ static char *get_cookies(SoupURI *soup_uri);
 static void load_all_cookies(void);
 static void new_generic_request(SoupSession *soup_ses, SoupMessage *soup_msg, gpointer unused);
 static void update_cookie_jar(SoupCookieJar *jar, SoupCookie *old, SoupCookie *new);
-static void handle_cookie_request(SoupMessage *soup_msg, gpointer unused);
+static void handle_response_headers(SoupMessage *soup_msg, gpointer unused);
 #endif
 
 Client client;
@@ -242,8 +243,11 @@ gboolean
 webview_mimetype_cb(WebKitWebView *webview, WebKitWebFrame *frame, WebKitNetworkRequest *request,
                         char *mime_type, WebKitWebPolicyDecision *decision, gpointer user_data) {
     if (webkit_web_view_can_show_mime_type(webview, mime_type) == FALSE) {
-        webkit_web_policy_decision_download(decision);
-        return TRUE;
+        if (http_status == 200) {
+            webkit_web_policy_decision_download(decision);
+            return TRUE;
+        }
+        return FALSE;
     } else {
         return FALSE;
     }
@@ -2793,9 +2797,9 @@ setup_cookies()
 			G_CALLBACK(update_cookie_jar), NULL);
 }
 
-/* TA:  XXX - we should be using this callback for any header-requests we
- *      receive (hence the name "new_generic_request" -- but for now, its use
- *      is limited to handling cookies.
+/* This function could be used for any header requests we receive
+ * for not, it's limited to handling cookies and checking the
+ * HTTP status
  */
 void
 new_generic_request(SoupSession *session, SoupMessage *soup_msg, gpointer unused) 
@@ -2813,7 +2817,7 @@ new_generic_request(SoupSession *session, SoupMessage *soup_msg, gpointer unused
         g_free(cookie_str);
     }
 
-    g_signal_connect_after(G_OBJECT(soup_msg), "got-headers", G_CALLBACK(handle_cookie_request), NULL);
+    g_signal_connect_after(G_OBJECT(soup_msg), "got-headers", G_CALLBACK(handle_response_headers), NULL);
 
     return;
 }
@@ -2828,12 +2832,14 @@ get_cookies(SoupURI *soup_uri) {
 }
 
 void
-handle_cookie_request(SoupMessage *soup_msg, gpointer unused)
+handle_response_headers(SoupMessage *soup_msg, gpointer unused)
 {
 	GSList *resp_cookie = NULL, *cookie_list;
 	SoupCookie *cookie;
 	SoupURI *uri = soup_message_get_uri(soup_msg);
 
+    http_status = soup_msg->status_code;
+
 	if (CookiePolicy != SOUP_COOKIE_JAR_ACCEPT_NEVER) {
 		cookie_list = soup_cookies_from_response(soup_msg);
 		for(resp_cookie = cookie_list; resp_cookie; resp_cookie = g_slist_next(resp_cookie))
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Vimprobable-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/vimprobable-users

Reply via email to