[gnome-boxes] Set a user-agent when using the network
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-boxes] Set a user-agent when using the network
- Date: Mon, 20 Nov 2017 16:29:59 +0000 (UTC)
commit d0c4afe35c2940167533e6ce8fe346d20d29e544
Author: Debarshi Ray <debarshir gnome org>
Date: Tue Nov 14 21:22:28 2017 +0100
Set a user-agent when using the network
The user-agent looks like this:
<distro-name>/<distro-version> <package-tarname>/<package-version>
The user agent is used with the Soup.Session when downloading ISOs and
assets (like logos), and passed as the "tag" parameter to the
developers.redhat.com end-point.
<distro-name> and <distro-version> default to "GNOME" and "3"
respectively. Build options have been added to enable distributors to
suitably override them.
<package-tarname> is always "gnome-boxes", and <package-version> is
determined by git-version-gen. So, tarball releases get a nice round
number based on the name of the tag, while development builds get a
unique version string based on the last commit hash. One drawback is
that distributors can't override the <package-version> for downstream
patches. An option can be added in future if this becomes a problem.
https://bugzilla.gnome.org/show_bug.cgi?id=790343
configure.ac | 16 ++++++++++++++++
meson.build | 2 ++
meson_options.txt | 10 ++++++++++
src/config.vapi | 2 ++
src/downloader.vala | 3 +++
src/util.vala | 7 +++++++
src/wizard-source.vala | 6 +++++-
7 files changed, 45 insertions(+), 1 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 8abff4d..d87c15e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -108,6 +108,20 @@ VALA_ADD_CHECKFILE([src/gnome_boxes_search_provider_vala.stamp])
VALA_ADD_CHECKFILE([libgd/gd-1.0.vapi])
+AC_ARG_WITH([distributor-name],
+ AS_HELP_STRING([--with-distributor-name], [Distributor name used in HTTP user agent]))
+
+AS_IF([test "x$with_distributor_name" = "x"], [with_distributor_name="GNOME"])
+AC_DEFINE_UNQUOTED([DISTRIBUTOR_NAME], ["$with_distributor_name"], [Distributor name used in HTTP user
agent])
+
+AC_ARG_WITH([distributor-version],
+ AS_HELP_STRING([--with-distributor-version], [Distributor version used in HTTP user agent]))
+
+AS_IF([test "x$with_distributor_version" = "x"], [with_distributor_version="3"])
+AC_DEFINE_UNQUOTED([DISTRIBUTOR_VERSION],
+ ["$with_distributor_version"],
+ [Distributor version used in HTTP user agent])
+
AC_ARG_ENABLE(ovirt,
AS_HELP_STRING([--enable-ovirt=yes|no|auto], [Enable support for OVirt]),
[enable_ovirt=$enableval],
@@ -208,6 +222,8 @@ AC_MSG_NOTICE([
prefix: ${prefix}
c compiler: ${CC} ${CFLAGS}
build from vala sources: $enable_vala
+ Distributor name: $with_distributor_name
+ Distributor version: $with_distributor_version
oVirt support: $have_govirt
Installed tests: $enable_installed_tests
])
diff --git a/meson.build b/meson.build
index 9d32260..80b2257 100644
--- a/meson.build
+++ b/meson.build
@@ -50,6 +50,8 @@ data_dir = join_paths (get_option ('prefix'), get_option ('datadir'))
locale_dir = join_paths (data_dir, '/locale')
conf = configuration_data ()
+conf.set_quoted ('DISTRIBUTOR_NAME', get_option ('distributor-name'))
+conf.set_quoted ('DISTRIBUTOR_VERSION', get_option ('distributor-version'))
conf.set_quoted ('PACKAGE_NAME', meson.project_name ())
conf.set_quoted ('PACKAGE_TARNAME', meson.project_name ())
conf.set_quoted ('PACKAGE_VERSION', meson.project_version ())
diff --git a/meson_options.txt b/meson_options.txt
index 92aa7d7..aa2ef3f 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -1,3 +1,13 @@
+option ('distributor-name',
+ type: 'string',
+ value: 'GNOME',
+ description: 'Distributor name used in HTTP user agent')
+
+option ('distributor-version',
+ type: 'string',
+ value: '3',
+ description: 'Distributor version used in HTTP user agent')
+
option ('enable-ovirt',
type: 'boolean',
value: true)
diff --git a/src/config.vapi b/src/config.vapi
index f462322..15e1eff 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -1,5 +1,7 @@
[CCode (cprefix = "", lower_case_cprefix = "", cheader_filename = "config.h")]
namespace Config {
+ public const string DISTRIBUTOR_NAME;
+ public const string DISTRIBUTOR_VERSION;
public const string PACKAGE_VERSION;
public const string PACKAGE_DATADIR;
public const string PACKAGE_TARNAME;
diff --git a/src/downloader.vala b/src/downloader.vala
index 6ca8251..ae870bd 100644
--- a/src/downloader.vala
+++ b/src/downloader.vala
@@ -55,6 +55,9 @@ private class Boxes.Downloader : GLib.Object {
session = new Soup.Session ();
if (Environment.get_variable ("SOUP_DEBUG") != null)
session.add_feature (new Soup.Logger (Soup.LoggerLogLevel.HEADERS, -1));
+
+ var user_agent = get_user_agent ();
+ session.user_agent = user_agent;
}
/**
diff --git a/src/util.vala b/src/util.vala
index 14aa741..28b7bf0 100644
--- a/src/util.vala
+++ b/src/util.vala
@@ -33,6 +33,13 @@ namespace Boxes {
return get_pkgdata ("osinfo");
}
+ public string get_user_agent () {
+ var user_agent = Config.DISTRIBUTOR_NAME + "/" + Config.DISTRIBUTOR_VERSION + " " +
+ Config.PACKAGE_TARNAME + "/" + Config.PACKAGE_VERSION;
+
+ return user_agent;
+ }
+
public string get_user_unattended (string? file_name = null) {
var dir = Path.build_filename (get_user_pkgconfig (), "unattended");
diff --git a/src/wizard-source.vala b/src/wizard-source.vala
index e207924..c88422d 100644
--- a/src/wizard-source.vala
+++ b/src/wizard-source.vala
@@ -522,7 +522,11 @@ private class Boxes.WizardSource: Gtk.Stack {
data_manager.clear.begin (WebKit.WebsiteDataTypes.COOKIES, 0, null);
});
- var authentication_uri = "https://developers.redhat.com/download-manager/rest/featured/file/rhel";
+ var user_agent = get_user_agent ();
+ var user_agent_escaped = GLib.Uri.escape_string (user_agent, null, false);
+ var authentication_uri = "https://developers.redhat.com/download-manager/rest/featured/file/rhel" +
+ "?tag=" + user_agent_escaped;
+
debug ("RHEL ISO authentication URI: %s", authentication_uri);
rhel_web_view.view.load_uri (authentication_uri);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]