[gnome-boxes] Download http directly via libsoup



commit 16cb6ed609ae32a386844d1c32e50e34b07b36c3
Author: Alexander Larsson <alexl redhat com>
Date:   Tue Sep 18 14:41:00 2012 +0200

    Download http directly via libsoup
    
    The GVfs http support works for this, but is quite overcomplicated for
    pure file downloads. Directly using libsoup means less dependencies
    and more direct codepaths (library calls instead of multiple
    cross-process dbus calls).
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684290

 configure.ac        |    3 +++
 src/Makefile.am     |    1 +
 src/downloader.vala |   13 ++++++++++++-
 3 files changed, 16 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 037c8b6..77dbfc7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -55,6 +55,7 @@ GUDEV_MIN_VERSION=165
 OSINFO_MIN_VERSION=0.2.0
 TRACKER_SPARQL=0.13.1
 UUID_REQUIRED=1.41.3
+LIBSOUP_REQUIRED=2.38
 
 PKG_CHECK_MODULES(BOXES, [
   clutter-gtk-1.0 >= $CLUTTER_GTK_MIN_VERSION
@@ -71,6 +72,7 @@ PKG_CHECK_MODULES(BOXES, [
   libosinfo-1.0 >= $OSINFO_MIN_VERSION
   tracker-sparql-0.14 >= $TRACKER_SPARQL
   uuid >= $UUID_REQUIRED
+  libsoup-2.4 >= $LIBSOUP_REQUIRED
 ])
 
 VALA_ADD_CHECKFILE([src/gnome_boxes_vala.stamp])
@@ -99,6 +101,7 @@ VALA_CHECK([0.17.2], [
   libxml-2.0
   posix
   spice-client-gtk-3.0
+  libsoup-2.4
 ])
 
 dnl libgd
diff --git a/src/Makefile.am b/src/Makefile.am
index d61310c..bf88e4a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,7 @@ AM_VALAFLAGS =						\
 	--pkg glib-2.0					\
 	--pkg gtk-vnc-2.0				\
 	--pkg gudev-1.0					\
+	--pkg libsoup-2.4             			\
 	--pkg libosinfo-1.0				\
 	--pkg libvirt-gconfig-1.0			\
 	--pkg libvirt-gobject-1.0			\
diff --git a/src/downloader.vala b/src/downloader.vala
index 6f12126..20bbf15 100644
--- a/src/downloader.vala
+++ b/src/downloader.vala
@@ -2,6 +2,7 @@
 
 private class Boxes.Downloader : GLib.Object {
     private static Downloader downloader;
+    private Soup.SessionAsync session;
 
     private GLib.HashTable<string,File> downloads;
 
@@ -36,6 +37,9 @@ private class Boxes.Downloader : GLib.Object {
 
     private Downloader () {
         downloads = new GLib.HashTable <string,File> (str_hash, str_equal);
+
+        session = new Soup.SessionAsync ();
+		session.add_feature_by_type (typeof (Soup.ProxyResolverDefault));
     }
 
     public async File download (File remote_file, string cached_path) throws GLib.Error {
@@ -55,7 +59,14 @@ private class Boxes.Downloader : GLib.Object {
         downloads.set (uri, cached_file);
 
         try {
-            yield remote_file.copy_async (cached_file, FileCopyFlags.NONE);
+            var msg = new Soup.Message ("GET", uri);
+            session.queue_message (msg, (session, msg) => {
+                download.callback ();
+            });
+            yield;
+            if (msg.status_code != Soup.KnownStatusCode.OK)
+                throw new Boxes.Error.INVALID (msg.reason_phrase);
+            yield cached_file.replace_contents_async (msg.response_body.data, null, false, 0, null, null);
         } catch (GLib.Error error) {
             download_failed (uri, cached_file, error);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]