[libgdata] core: Add gzip encoding support
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgdata] core: Add gzip encoding support
- Date: Sun, 24 Aug 2014 16:16:44 +0000 (UTC)
commit 6e89b033b33fcc8e8316e58f0ee28f3809ca9667
Author: Philip Withnall <philip withnall collabora co uk>
Date: Sun Aug 24 17:14:32 2014 +0100
core: Add gzip encoding support
libsoup already transparently supported gzip encoding of data from the
server, using SoupContentDecoder, which is present by default in a
SoupSession. We were correctly sending the Accept-Encoding header, but
Google also require that the string ‘gzip’ be present in the User-Agent
header to enable gzip support.
Add a User-Agent header which supports this.
https://bugzilla.gnome.org/show_bug.cgi?id=666623
gdata/gdata-service.c | 23 +++++++++++++++++++++++
1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index 78600e2..8ac96ed 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -2290,6 +2290,24 @@ _gdata_service_get_log_level (void)
return level;
}
+/* Build a User-Agent value to send to the server.
+ *
+ * If we support gzip, we can request gzip from the server by both including
+ * the appropriate Accept-Encoding header and putting 'gzip' in the User-Agent
+ * header:
+ * - https://developers.google.com/drive/web/performance#gzip
+ * - http://googleappsdeveloper.blogspot.co.uk/2011/12/optimizing-bandwidth-usage-with-gzip.html
+ */
+static gchar *
+build_user_agent (gboolean supports_gzip)
+{
+ if (supports_gzip) {
+ return g_strdup_printf ("libgdata/%s - gzip", VERSION);
+ } else {
+ return g_strdup_printf ("libgdata/%s", VERSION);
+ }
+}
+
/**
* _gdata_service_build_session:
*
@@ -2305,6 +2323,7 @@ _gdata_service_build_session (void)
{
SoupSession *session;
gboolean ssl_strict = TRUE;
+ gchar *user_agent;
/* Iff LIBGDATA_LAX_SSL_CERTIFICATES=1, relax SSL certificate validation to allow using
invalid/unsigned certificates for testing. */
if (g_strcmp0 (g_getenv ("LIBGDATA_LAX_SSL_CERTIFICATES"), "1") == 0) {
@@ -2315,6 +2334,10 @@ _gdata_service_build_session (void)
"timeout", 0,
NULL);
+ user_agent = build_user_agent (soup_session_has_feature (session, SOUP_TYPE_CONTENT_DECODER));
+ g_object_set (session, "user-agent", user_agent, NULL);
+ g_free (user_agent);
+
soup_session_add_feature_by_type (session, SOUP_TYPE_PROXY_RESOLVER_DEFAULT);
/* Log all libsoup traffic if debugging's turned on */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]