oduwsdl/MementoEmbed

Endpoints do not correctly support URI-Ms containing query strings

Closed this issue · 0 comments

MementoEmbed trims the query string off of URI-Ms:

The problem exists in all services due to an incorrect assumption of how the path:subpath variable is handled by Flask. Code for the social card service is below:

@bp.route('/services/product/socialcard/<path:subpath>')
def socialcard_endpoint(subpath):
urim = subpath
prefs = {}
prefs['datauri_favicon'] = 'no'
prefs['datauri_image'] = 'no'
if 'Prefer' in request.headers:
preferences = request.headers['Prefer'].split(',')
for pref in preferences:
key, value = pref.split('=')
prefs[key] = value.lower()
return handle_errors(generate_socialcard_response, urim, prefs)

Instead of returning the rest of the path within the variable subpath on line 110, Flask instead strips off the query string and stores it in the args array of its request object. The path method of the request object does not have the query string, either.

This can be fixed by:

  • rebuilding the URI-M using the query_string member of the request object
  • getting the full path requested from the full_path member of the request object and removing the service endpoint from this string, essentially ignoring the <path:subpath> capabilities of Flask altogether, replacing line 110 with something like
    • option 1: urim = request.full_path.replace('/services/product/socialcard/', '') - this can be made service-specific
    • option 2: urim = request.full_path[29:] - this is also service specific, but avoids any potential string collisions with the actual URI-M

This will also have to be repeated for all service endpoints:

  • /services/product/thumbnail/
  • /services/product/socialcard/
  • /services/memento/contentdata/
  • /services/memento/bestimage/
  • /services/memento/archivedata/
  • /services/memento/originalresourcedata/