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

KeyError on content-type in ckanext/resourceproxy/blueprint.py #7101

Open
twdbben opened this issue Sep 22, 2022 · 0 comments
Open

KeyError on content-type in ckanext/resourceproxy/blueprint.py #7101

twdbben opened this issue Sep 22, 2022 · 0 comments
Assignees

Comments

@twdbben
Copy link

twdbben commented Sep 22, 2022

CKAN version
Current master

Describe the bug

The problem is a KeyError on content-type in this line of code:

response.headers[u'content-type'] = r.headers[u'content-type']

proxy_resource() is failing with a KeyError in the case that the remote server is misconfigured to not include a content-type header on the file being proxied.

In my case it is due to an Apache server not configured with an AddType statement to serve geojson files correctly.

This should be corrected on the offending server, but it would be nice if CKAN responded with a proper error instead of a stack trace.

I am not sure whether this should be fixed by either:

  1. Catching the KeyError and aborting with a 409 error when this happens, or
  2. Setting response.headers[u'content-type'] to a default value when no value is present in the header

I'm happy to submit a pull request with this fix if someone can give me guidance on which way this should be fixed.

Steps to reproduce

Expected behavior

I'd suggest a 409 error saying something like "Resource is not being served with a content-type header"

Additional details

KeyError: 'content-type'

Traceback (most recent call last)
File "/usr/lib/ckan/default/lib/python3.8/site-packages/flask/app.py", line 2449, in wsgi_app
response = self.handle_exception(e)
File "/usr/lib/ckan/default/lib/python3.8/site-packages/flask/app.py", line 1866, in handle_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/ckan/default/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/lib/ckan/default/lib/python3.8/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/usr/lib/ckan/default/lib/python3.8/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/lib/ckan/default/lib/python3.8/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/lib/ckan/default/lib/python3.8/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/lib/ckan/default/lib/python3.8/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/lib/ckan/default/lib/python3.8/site-packages/flask_debugtoolbar/init.py", line 125, in dispatch_request
return view_func(**req.view_args)
File "/usr/lib/ckan/default/src/ckan/ckanext/resourceproxy/blueprint.py", line 117, in proxy_view
return proxy_resource(context, data_dict)
File "/usr/lib/ckan/default/src/ckan/ckanext/resourceproxy/blueprint.py", line 71, in proxy_resource
response.headers[u'content-type'] = r.headers[u'content-type']
File "/usr/lib/ckan/default/lib/python3.8/site-packages/requests/structures.py", line 54, in getitem

KeyError: 'content-type'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants