Issue #875 resolved

Spaces (%20) in "path" don't work.

Anonymous created an issue

If a space character is in a path (URI), splitting the request_line by the space character fails with an error similar to below:

{{{ Traceback (most recent call last): File "/usr/lib/python2.5/site-packages/cherrypy/wsgiserver/init.py", line 992, in communicate req.parse_request() File "/usr/lib/python2.5/site-packages/cherrypy/wsgiserver/init.py", line 304, in parse_request self._parse_request() File "/usr/lib/python2.5/site-packages/cherrypy/wsgiserver/init.py", line 386, in _parse_request rp = int(req_protocol[5]), int(req_protocol[7]) ValueError: invalid literal for int() with base 10: 'm' }}}

In other words, req_protocol is being set to something else.

A solution may be to find the first space, and then find the last space, and break the request_line into method, path, request_protocol.

Reported by courier@braydon.com

Comments (10)

  1. Anonymous

    In file wsgiserver/init.py, changing line 335:

    method, path, req_protocol = request_line.strip().split(" ", 2)
    

    To the lines:

    s_a = request_line.find(" ")
    s_z = request_line.rfind(" ")
    method = request_line[0:s_a].strip()
    path = request_line[s_a:s_z].strip()
    req_protocol = request_line[s_z:-1].strip()
    

    Fixed the problem.

  2. Anonymous

    If a space character does get into the path rather than %20 in the Request-Line, [2041] fix won't catch it because there wouldn't be a ValueError. req_protocol will be set to something like "bar HTTP/1.1" from the Request-Line "GET /foo bar HTTP/1.1", causing the same error as in the description above. Could we make sure there are *only* 2 spaces in the Request-Line and then raise a Malformed Request-Line error?

    BTW, I was getting this will proxy-passing a CherryPy server through Nginx. It was doing the same thing in all the browsers I use; Iceweasel, Epiphany, and Galeon.

  3. Anonymous

    Sorry, it *was* being proxy-passed in Nginx. now it's being proxied through Apache and that is when the problem came up.

  4. Log in to comment