You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Catching the KeyError and aborting with a 409 error when this happens, or
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.
Try to view the resource in CKAN using the geojson_view plugin
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'
The text was updated successfully, but these errors were encountered:
CKAN version
Current master
Describe the bug
The problem is a KeyError on content-type in this line of code:
ckan/ckanext/resourceproxy/blueprint.py
Line 71 in 367fed2
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:
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'
The text was updated successfully, but these errors were encountered: