Skip to content

Commit

Permalink
Use https by default with MB 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 musicbrainz.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.

Fixes alastair#197

Signed-off-by: Frederik “Freso” S. Olesen <freso.dk@gmail.com>
  • Loading branch information
Freso authored and Horrendus committed Aug 16, 2020
1 parent 6666cfd commit e5de3bd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions musicbrainzngs/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def _decorator(func):

user = password = ""
hostname = "musicbrainz.org"
https = True
_client = ""
_useragent = ""

Expand All @@ -324,12 +325,14 @@ def set_useragent(app, version, contact=None):
_client = "%s-%s" % (app, version)
_log.debug("set user-agent to %s" % _useragent)

def set_hostname(new_hostname):
def set_hostname(new_hostname, use_https=False):
"""Set the hostname for MusicBrainz webservice requests.
Defaults to 'musicbrainz.org'.
You can also include a port: 'localhost:8000'."""
global hostname
global https
hostname = new_hostname
https = use_https

# Rate limiting.

Expand Down Expand Up @@ -633,7 +636,7 @@ def _mb_request(path, method='GET', auth_required=AUTH_NO,
# Construct the full URL for the request, including hostname and
# query string.
url = compat.urlunparse((
'http',
'https' if https else 'http',
hostname,
'/ws/2/%s' % path,
'',
Expand Down

0 comments on commit e5de3bd

Please sign in to comment.