Skip to content

Exception on empty header list #5

Open
@damjankuznar

Description

@damjankuznar

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions