Skip to content

Adding Cookbook content negotiation #20

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

Merged
merged 1 commit into from
Aug 14, 2020
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
14 changes: 14 additions & 0 deletions .ebextensions/nginx/conf.d/elasticbeanstalk/00_application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,20 @@ location / {
}
}

location /api/cookbook/recipe/0057-publishing-v2-and-v3/manifest.json {
resolver 8.8.8.8;
proxy_ssl_verify off;
proxy_ssl_server_name on;
proxy_set_header Host 'preview.iiif.io';
proxy_hide_header x-amz-id-2;
proxy_hide_header x-amz-request-id;
proxy_intercept_errors on;
proxy_pass https://preview.iiif.io:443/cookbook/0057-conneg/recipe/0057-publishing-v2-and-v3/manifest-$version.json;
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 ^~ /api/ {
# do json to json ld mime type conversion
# do presentation service
Expand Down
6 changes: 6 additions & 0 deletions .ebextensions/nginx/conf.d/jsonldmap.conf
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ map $uri $custom_content_type {
default "text/html";
~(.*\.xml)$ "application/rdf+xml";
}

map $http_accept $version {
default "v3";
"~http://iiif.io/api/presentation/2/context.json" "v2";
"~http://iiif.io/api/presentation/3/context.json" "v3";
}
2 changes: 1 addition & 1 deletion tests/TestHttps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/local/bin/python3.6
#!/usr/bin/env python3
import unittest
import os
import requests
Expand Down
20 changes: 20 additions & 0 deletions tests/TestJsonLD.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from urllib2 import urlopen
from urllib import request
import os
import json

class TestJsonLD(unittest.TestCase):
baseurl = ''
Expand All @@ -27,5 +28,24 @@ def test_jsonldmimetype(self):
mimetype=response.info().get('Content-type')
self.assertEqual(mimetype, 'application/ld+json', 'Mimetype should be jsonld if I support jsonld')

def test_cookbook_manifest(self):
url = '%s/%s' % (self.baseurl, 'api/cookbook/recipe/0057-publishing-v2-and-v3/manifest.json')
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')

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')

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')


if __name__ == '__main__':
unittest.main()
6 changes: 3 additions & 3 deletions tests/TestRedirect.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ def test_api(self):

def test_image(self):
url = '%s/%s' % (self.baseurl, 'api/image/')
dest = '%s/%s' % (self.desturl, 'api/image/2.1/')
dest = '%s/%s' % (self.desturl, 'api/image/3.0/')
self.checkRedirect(url, dest)

def test_presentation(self):
url = '%s/%s' % (self.baseurl, 'api/presentation/index.html')
dest = '%s/%s' % (self.desturl, 'api/presentation/2.1/')
dest = '%s/%s' % (self.desturl, 'api/presentation/3.0/')
self.checkRedirect(url, dest)
def test_validator(self):
url = '%s/%s' % (self.baseurl, 'api/presentation/validator')
Expand Down Expand Up @@ -81,7 +81,7 @@ def test_search(self):
self.checkRedirect(url, dest)
def test_api_redirect(self):
url = '%s/%s' % (self.baseurl, 'api/image/')
dest = '%s/%s' % ('https://iiif.io', 'api/image/2.1/')
dest = '%s/%s' % ('https://iiif.io', 'api/image/3.0/')
self.checkRedirect(url, dest, True)

def test_editor_policy(self):
Expand Down