Skip to content

Commit

Permalink
Merge 9570e88 into 4a7edaf
Browse files Browse the repository at this point in the history
  • Loading branch information
glenrobson committed Aug 20, 2019
2 parents 4a7edaf + 9570e88 commit d61a144
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions iiif_validator/tests/baseurl_redirect.py
Expand Up @@ -2,9 +2,11 @@
try:
# python3
from urllib.request import Request, urlopen, HTTPError
print ('Importing 3')
except ImportError:
# fall back to python2
from urllib2 import Request, urlopen, HTTPError
print ('Importing 2')


class Test_Baseurl_Redirect(BaseTest):
Expand All @@ -17,16 +19,24 @@ class Test_Baseurl_Redirect(BaseTest):
def run(self, result):
url = result.make_info_url()
url = url.replace('/info.json', '')
newurl = ''
try:
r = Request(url)
wh = urlopen(r)
img = wh.read()
wh.close()
newurl = wh.geturl()
except HTTPError as e:
wh = e
if wh.getcode() >= 300 and wh.getcode() < 400:
newurl = wh.headers['Location']
else:
newurl = wh.geturl()

u = wh.geturl()
if u == url:
if newurl == url:
print (wh)
print (wh.geturl())
print (type(wh))
# we didn't redirect
raise ValidatorError('redirect', u, '{}/info.json'.format(url), result, 'Failed to redirect from {} to {}/info.json. Response code {}'.format(u, url, wh.getcode()))
else:
Expand Down

0 comments on commit d61a144

Please sign in to comment.