Skip to content

Commit

Permalink
Allow wsgiref to reconstruct URIs per the WSGI spec
Browse files Browse the repository at this point in the history
Instead of reimplementing URL reconstruction for logging purposes, and
getting it wrong over and over and over, let's just use wsgiref.util.

Change-Id: Ib64877c35ad856bdef8f64f6df44a054eaa2321b
Closes-Bug: 1448286
  • Loading branch information
dolph committed Apr 24, 2015
1 parent ce6f0fc commit f2a7586
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions keystone/common/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import copy
import itertools
import urllib
import wsgiref.util

from oslo_config import cfg
import oslo_i18n
Expand Down Expand Up @@ -227,13 +227,10 @@ def __call__(self, req):
# NOTE(morganfainberg): use the request method to normalize the
# response code between GET and HEAD requests. The HTTP status should
# be the same.
req_method = req.environ['REQUEST_METHOD'].upper()
path = req.environ.get('RAW_PATH_INFO') or req.environ['PATH_INFO']
LOG.info('%(req_method)s %(path)s%(params)s', {
'req_method': req_method,
'path': path,
'params': '?' + urllib.urlencode(req.params) if req.params else ''}
)
LOG.info('%(req_method)s %(uri)s', {
'req_method': req.environ['REQUEST_METHOD'].upper(),
'uri': wsgiref.util.request_uri(req.environ),
})

params = self._normalize_dict(params)

Expand Down Expand Up @@ -272,7 +269,7 @@ def __call__(self, req):

response_code = self._get_response_code(req)
return render_response(body=result, status=response_code,
method=req_method)
method=req.environ['REQUEST_METHOD'])

def _get_response_code(self, req):
req_method = req.environ['REQUEST_METHOD']
Expand Down Expand Up @@ -776,7 +773,7 @@ def render_response(body=None, status=None, headers=None, method=None):
status='%s %s' % status,
headerlist=headers)

if method == 'HEAD':
if method and method.upper() == 'HEAD':
# NOTE(morganfainberg): HEAD requests should return the same status
# as a GET request and same headers (including content-type and
# content-length). The webob.Response object automatically changes
Expand Down

0 comments on commit f2a7586

Please sign in to comment.