Skip to content

Commit

Permalink
Merge pull request #36 from IIIF/fix-vtt-cors
Browse files Browse the repository at this point in the history
Fix VTT CORS
  • Loading branch information
glenrobson authored Apr 26, 2024
2 parents 71c3316 + f5621f3 commit 913a488
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,14 @@ location ^~ /api/ {
add_header 'Cache-Control' 'public, no-transform, max-age=2419200';
add_header "X-UA-Compatible" "IE=Edge,chrome=1";
}

location ~ \.vtt$ {
include conf.d/elasticbeanstalk/subfiles/iiif-website.conf;
proxy_hide_header 'Content-Type';
add_header 'Content-Type' 'text/vtt';
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Cache-Control' 'public, no-transform, max-age=2419200';
add_header "X-UA-Compatible" "IE=Edge,chrome=1";
}
}
location =/apple-touch-icon-precomposed.png {
access_log off;
Expand Down
13 changes: 13 additions & 0 deletions tests/TestCORS.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ def test_xml_cors(self):

self.assertEqual(response.headers['Content-Type'],"text/xml", 'Expected header Content-Type: text/xml but was Content-Type: %s' % (response.headers['Content-Type']))

def test_vtt_cors(self):
url = "%s/%s" % (self.baseurl, 'api/cookbook/recipe/0074-multiple-language-captions/Per_voi_signore_Modelli_francesi_en.vtt')

response = requests.get(url, allow_redirects=False)
code = response.status_code
self.assertEqual(code,200, 'Failed to get required vtt file for CORS testing. Got response %s from URL %s' % (code, url))

# Check CORS headers
self.assertTrue('Access-Control-Allow-Origin' in response.headers, 'Missing Access-Control-Allow-Origin header from %s' % url)
self.assertEqual(response.headers['Access-Control-Allow-Origin'],"*", 'Expected header Access-Control-Allow-Origin:* but was Access-Control-Allow-Origin:%s' % (response.headers['Access-Control-Allow-Origin']))

self.assertEqual(response.headers['Content-Type'],"text/vtt", 'Expected header Content-Type: text/vtt but was Content-Type: %s' % (response.headers['Content-Type']))

def test_single_cors(self):
url = "%s/%s" % (self.baseurl, 'api/cookbook/recipe/0003-mvm-video/manifest.json')

Expand Down
7 changes: 4 additions & 3 deletions tests/TestJsonLD.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,22 @@ def test_jsonldmimetype(self):

def test_cookbook_manifest(self):
url = '%s/%s' % (self.baseurl, 'api/cookbook/recipe/0057-publishing-v2-and-v3/manifest.json')
print (url)
with urlopen(url) as urlPointer:
manifest = json.loads(urlPointer.read().decode())
self.assertEquals(manifest['@context'], 'http://iiif.io/api/presentation/3/context.json', 'Expected default retrieval of manifest to be version 3')
self.assertEqual(manifest['@context'], 'http://iiif.io/api/presentation/3/context.json', 'Expected default retrieval of manifest to be version 3')

opener = request.build_opener()
opener.addheaders = [('Accept', "application/ld+json;profile=http://iiif.io/api/presentation/3/context.json")]
with opener.open(url) as urlPointer:
manifest = json.loads(urlPointer.read().decode())
self.assertEquals(manifest['@context'], 'http://iiif.io/api/presentation/3/context.json', 'Passing the 3 accept header should get version 3 but got version 2')
self.assertEqual(manifest['@context'], 'http://iiif.io/api/presentation/3/context.json', 'Passing the 3 accept header should get version 3 but got version 2')

opener = request.build_opener()
opener.addheaders = [('Accept', "application/ld+json;profile=http://iiif.io/api/presentation/2/context.json")]
with opener.open(url) as urlPointer:
manifest = json.loads(urlPointer.read().decode())
self.assertEquals(manifest['@context'], 'http://iiif.io/api/presentation/2/context.json', 'Passing the 2 accept header should get version 2 manifest')
self.assertEqual(manifest['@context'], 'http://iiif.io/api/presentation/2/context.json', 'Passing the 2 accept header should get version 2 manifest')


if __name__ == '__main__':
Expand Down

0 comments on commit 913a488

Please sign in to comment.