Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix VTT CORS #36

Merged
merged 6 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading