qualityvis icon indicating copy to clipboard operation
qualityvis copied to clipboard

Exception on empty header list

Open damjankuznar opened this issue 11 years ago • 0 comments

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.

damjankuznar avatar Feb 17 '14 07:02 damjankuznar