Pass cookies to Aria2

This commit is contained in:
André Stösel 2012-04-05 21:25:50 +02:00 committed by Christian Dywan
parent 8bba8f9aad
commit b5d5c17396

View file

@ -25,12 +25,13 @@ namespace EDM {
public string uri; public string uri;
public string auth; public string auth;
public string referer; public string referer;
public SList<Cookie> cookies; public string? cookie_header;
} }
internal Manager manager; internal Manager manager;
private class Manager : GLib.Object { private class Manager : GLib.Object {
private CookieJar cookie_jar;
private GLib.PtrArray download_managers = new GLib.PtrArray (); private GLib.PtrArray download_managers = new GLib.PtrArray ();
public bool download_requested (Midori.View view, WebKit.Download download) { public bool download_requested (Midori.View view, WebKit.Download download) {
@ -41,11 +42,11 @@ namespace EDM {
var request = download.get_network_request (); var request = download.get_network_request ();
var message = request.get_message (); var message = request.get_message ();
var headers = message.request_headers; weak MessageHeaders headers = message.request_headers;
dlReq.auth = headers.get ("Authorization"); dlReq.auth = headers.get ("Authorization");
dlReq.referer = headers.get ("Referer"); 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++) { for (var i = 0 ; i < download_managers.len; i++) {
var dm = download_managers.index (i) as ExternalDownloadManager; var dm = download_managers.index (i) as ExternalDownloadManager;
@ -96,6 +97,11 @@ namespace EDM {
app.add_browser.disconnect (browser_added); 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 { private abstract class ExternalDownloadManager : Midori.Extension {
@ -120,6 +126,14 @@ namespace EDM {
referer.set_string (dlReq.referer); referer.set_string (dlReq.referer);
options.insert ("referer", 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", var message = XMLRPC.request_new ("http://127.0.0.1:6800/rpc",
"aria2.addUri", "aria2.addUri",
typeof (ValueArray), url, typeof (ValueArray), url,