[Xfce4-commits] <midori:master> Pass cookies to Aria2

Christian Dywan noreply at xfce.org
Thu Apr 5 22:46:04 CEST 2012


Updating branch refs/heads/master
         to b5d5c17396d5b3dde434afda636bc04cae41f64d (commit)
       from 8bba8f9aadb085264d2c3d74bd47a70e957c902a (commit)

commit b5d5c17396d5b3dde434afda636bc04cae41f64d
Author: André Stösel <andre at stoesel.de>
Date:   Thu Apr 5 21:25:50 2012 +0200

    Pass cookies to Aria2

 extensions/external-download-manager.vala |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)

diff --git a/extensions/external-download-manager.vala b/extensions/external-download-manager.vala
index 1d837ab..62151da 100644
--- a/extensions/external-download-manager.vala
+++ b/extensions/external-download-manager.vala
@@ -25,12 +25,13 @@ namespace EDM {
         public string uri;
         public string auth;
         public string referer;
-        public SList<Cookie> cookies;
+        public string? cookie_header;
     }
 
     internal Manager manager;
 
     private class Manager : GLib.Object {
+        private CookieJar cookie_jar;
         private GLib.PtrArray download_managers =  new GLib.PtrArray ();
 
         public bool download_requested (Midori.View view, WebKit.Download download) {
@@ -41,11 +42,11 @@ namespace EDM {
 
                 var request = download.get_network_request ();
                 var message = request.get_message ();
-                var headers = message.request_headers;
+                weak MessageHeaders headers = message.request_headers;
 
                 dlReq.auth = headers.get ("Authorization");
                 dlReq.referer = headers.get ("Referer");
-                dlReq.cookies = cookies_from_request (message);
+                dlReq.cookie_header = this.cookie_jar.get_cookies (new Soup.URI (dlReq.uri), true);
 
                 for (var i = 0 ; i < download_managers.len; i++) {
                     var dm = download_managers.index (i) as ExternalDownloadManager;
@@ -96,6 +97,11 @@ namespace EDM {
                 app.add_browser.disconnect (browser_added);
             }
         }
+
+        construct {
+            var session = WebKit.get_default_session ();
+            this.cookie_jar = session.get_feature (typeof (CookieJar)) as CookieJar;
+        }
     }
 
     private abstract class ExternalDownloadManager : Midori.Extension {
@@ -113,13 +119,21 @@ namespace EDM {
     private class Aria2 : ExternalDownloadManager {
         public override bool download (DownloadRequest dlReq) {
             var url = value_array_new ();
-            value_array_insert (url, 0, typeof(string), dlReq.uri);
+            value_array_insert (url, 0, typeof (string), dlReq.uri);
 
             var options = value_hash_new ();
             var referer = new GLib.Value (typeof (string));
             referer.set_string (dlReq.referer);
             options.insert ("referer", referer);
 
+            var headers = value_array_new ();
+            if (dlReq.cookie_header != null) {
+                value_array_insert (headers, 0, typeof (string), "Cookie: %s".printf(dlReq.cookie_header));
+            }
+
+            if (headers.n_values > 0)
+               options.insert ("header", headers);
+
             var message = XMLRPC.request_new ("http://127.0.0.1:6800/rpc",
                 "aria2.addUri",
                 typeof (ValueArray), url,


More information about the Xfce4-commits mailing list