Skip to content

Commit

Permalink
Use https by default with CAA but not for custom servers
Browse files Browse the repository at this point in the history
This adds a new "global" `https` boolean variable. This variable will be
True by default, but if `set_hostname()` gets called it will default to
False. This should allow both using coverartarchive.org over HTTPS by
default, but anyone that have a script setting a custom server (that may
not support HTTPS) will continue to work as well.

Related to alastair#197

Signed-off-by: Frederik “Freso” S. Olesen <freso.dk@gmail.com>
  • Loading branch information
Freso committed Feb 21, 2019
1 parent e0b33f0 commit 472222c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions musicbrainzngs/caa.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
from musicbrainzngs.util import _unicode

hostname = "coverartarchive.org"
https = True


def set_caa_hostname(new_hostname):
def set_caa_hostname(new_hostname, use_https=False):
"""Set the base hostname for Cover Art Archive requests.
Defaults to 'coverartarchive.org'."""
global hostname
global https
hostname = new_hostname
https = use_https


def _caa_request(mbid, imageid=None, size=None, entitytype="release"):
Expand All @@ -46,7 +49,7 @@ def _caa_request(mbid, imageid=None, size=None, entitytype="release"):
elif imageid:
path.append(imageid)
url = compat.urlunparse((
'http',
'https' if https else 'http',
hostname,
'/%s' % '/'.join(path),
'',
Expand Down

0 comments on commit 472222c

Please sign in to comment.