diff options
| author | Mark McLoughlin <markmc@redhat.com> | 2012-07-23 09:32:30 +0100 |
|---|---|---|
| committer | Mark McLoughlin <markmc@redhat.com> | 2012-07-23 09:42:59 +0100 |
| commit | 9ac962cc82ef55cf211c0dfa5d18bc5bde27563b (patch) | |
| tree | 361dc5a43decb5a7be96f7b920e18ab357367500 /nova/api | |
| parent | c94cbe223fffa57969d91219538bc3576e9893da (diff) | |
| download | nova-9ac962cc82ef55cf211c0dfa5d18bc5bde27563b.tar.gz nova-9ac962cc82ef55cf211c0dfa5d18bc5bde27563b.tar.xz nova-9ac962cc82ef55cf211c0dfa5d18bc5bde27563b.zip | |
Avoid unrecognized content-type message
Fixes bug #904473
If the client does not include a Content-type header in its request
(which is normal for e.g. GET and DELETE) then eventlet will pass us
'text/plain'.
Because 'text/plain' isn't one of our supported request content types
we log:
Unrecognized Content-Type provided in request
This can be an annoying red-herring for people debugging issues.
The reason that eventlet defaults to text/plain is because it uses
the mimetools.Message.gettype() method:
Message.gettype()
Return the message type [..] as specified in the Content-Type
header. If no such header exists, return 'text/plain'.
The wsgiref web server has the same behavior, whereas mod_wsgi will
pass no content-type and twisted will pass an empty string.
Make our code more robust by treating the empty string or text/plain
as if no content-type header was supplied.
Change-Id: Ide117c807db0dc0f5cbe974788b604b5e236800a
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/wsgi.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index fb25c5caa..e92954711 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -140,10 +140,15 @@ class Request(webob.Request): if not "Content-Type" in self.headers: return None - allowed_types = SUPPORTED_CONTENT_TYPES content_type = self.content_type - if content_type not in allowed_types: + # NOTE(markmc): text/plain is the default for eventlet and + # other webservers which use mimetools.Message.gettype() + # whereas twisted defaults to ''. + if not content_type or content_type == 'text/plain': + return None + + if content_type not in SUPPORTED_CONTENT_TYPES: raise exception.InvalidContentType(content_type=content_type) return content_type |
