From b93bf8fcb0828154f10391484ae42fbcabf8bb2b Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 19 Jan 2016 15:36:16 +0200 Subject: Fix lack of HTTPS support in fetching code --- bpkg/fetch.cxx | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'bpkg/fetch.cxx') diff --git a/bpkg/fetch.cxx b/bpkg/fetch.cxx index 946d7e1..c47fb55 100644 --- a/bpkg/fetch.cxx +++ b/bpkg/fetch.cxx @@ -464,15 +464,24 @@ namespace bpkg } } + using protocol = repository_location::protocol; + static string - to_url (const string& host, uint16_t port, const path& file) + to_url (protocol proto, const string& host, uint16_t port, const path& file) { assert (file.relative ()); if (*file.begin () == "..") fail << "invalid URL path " << file; - string url ("http://"); + string url; + + switch (proto) + { + case protocol::http: url = "http://"; break; + case protocol::https: url = "https://"; break; + } + url += host; if (port != 0) @@ -485,6 +494,7 @@ namespace bpkg static path fetch_file (const common_options& o, + protocol proto, const string& host, uint16_t port, const path& f, @@ -495,7 +505,7 @@ namespace bpkg if (exists (r)) fail << "file " << r << " already exists"; - string url (to_url (host, port, f)); + string url (to_url (proto, host, port, f)); auto_rm arm (r); process pr (start (o, url, r)); @@ -516,12 +526,13 @@ namespace bpkg template static M fetch_manifest (const common_options& o, + protocol proto, const string& host, uint16_t port, const path& f, bool ignore_unknown) { - string url (to_url (host, port, f)); + string url (to_url (proto, host, port, f)); process pr (start (o, url)); try @@ -653,7 +664,8 @@ namespace bpkg path f (rl.path () / repositories); return rl.remote () - ? fetch_manifest (o, rl.host (), rl.port (), f, iu) + ? fetch_manifest ( + o, rl.proto (), rl.host (), rl.port (), f, iu) : fetch_manifest (f, iu); } @@ -675,7 +687,8 @@ namespace bpkg path f (rl.path () / packages); return rl.remote () - ? fetch_manifest (o, rl.host (), rl.port (), f, iu) + ? fetch_manifest ( + o, rl.proto (), rl.host (), rl.port (), f, iu) : fetch_manifest (f, iu); } @@ -700,7 +713,7 @@ namespace bpkg } return rl.remote () - ? fetch_file (o, rl.host (), rl.port (), f, d) + ? fetch_file (o, rl.proto (), rl.host (), rl.port (), f, d) : fetch_file (f, d); } } -- cgit v1.1