[openstack-dev] [glance] content-type always set to application/octet-stream

Carlos Konstanski ckonstanski at pippiandcarlos.com
Fri Nov 11 17:17:09 UTC 2016


glance --version : 2.5.0
File: common/http.py
Class: _BaseHTTPClient
Method: _set_common_request_kwargs
Python version: 3.4

First problem
-------------

There is a line of code in this method that fetches the Content-Type
header from the passed-in headers dict:

content_type = headers.get('content-type', 'application/octet-stream')

However it fails because the headers dict has strings that are not
represented as unicode:

(Pdb) print(headers)
{b'Content-Type': b'application/openstack-images-v2.1-json-patch'}

Therefore the lookup fails:

(Pdb) print(headers.get("Content-Type"))
None

But if we use a key that is coerced to the right type, it works:

(Pdb) print(headers.get(b"Content-Type"))
b'application/openstack-images-v2.1-json-patch'

The question I have yet to answer is: are these strings supposed to be
char sequences, or did they get converted by mistake due to a different
bug? That's really the first thing to figure out.

Second problem
--------------

The headers.get() call gets the case wrong. It should be Content-Type,
but instead it uses content-type.

Path to fix
-----------

I would be happy to fix this. This would be my first upstream
contribution, and I know there is a process to even get to square
one. Should I start down that path, or does someone else wish to address
this bug?

Sincerely,
Carlos Konstanski



More information about the OpenStack-dev mailing list