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

Endpoints do not correctly support URI-Ms containing query strings #126

Closed
shawnmjones opened this Issue Sep 5, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@shawnmjones
Collaborator

shawnmjones commented Sep 5, 2018

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/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment