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

Exception on empty header list #5

Open
damjankuznar opened this issue Feb 17, 2014 · 0 comments
Open

Exception on empty header list #5

damjankuznar opened this issue Feb 17, 2014 · 0 comments

Comments

@damjankuznar
Copy link

I am using Bottle v0.12.3 and encounter the following exception when I install the compression plugin.

Traceback (most recent call last):
  File "/path/to/bottle.py", line 862, in _handle
    return route.call(**args)
  File "/path/to/bottle.py", line 1727, in wrapper
    rv = callback(*a, **ka)
  File "/path/to/bottle_compressor.py", line 190, in wrapper
    ctype = content_type.split(';')[0]
AttributeError: 'NoneType' object has no attribute 'split'

As it turns out, the problem is with this block of code when the content type is not set explicitly in routes, since the Bottle response object returns None for Content-Type in that case.

# ignore non-compressable types
content_type = response.headers.get('Content-Type') # <- fails here
ctype = content_type.split(';')[0]
if ctype not in content_types:
    return data

I managed to get it working by replacing the line

content_type = response.headers.get('Content-Type') # <- fails here

with

content_type = dict(response.headerlist)["Content-Type"]

since the headerlist does contain the default content type (text/htm).

This could also be viewed as a Bottle bug, since it would be sensible that the header property would return the default content type in case it is not set explicitly in the route.

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

1 participant