# Buggy code
def parse_request_line(self, line):
    bits = line.split(None, 2)
    if len(bits) != 3:
        raise InvalidRequestLine(line)

    # Method
    if not METH_RE.match(bits[0]):
        raise InvalidRequestMethod(bits[0])
    self.method = bits[0].upper()

    # URI
    # When the path starts with //, urlsplit considers it as a
    # relative uri while the RDF says it shouldnt
    # http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2
    # considers it as an absolute url.
    # fix issue #297
    if bits[1].startswith("//"):
        self.uri = bits[1][1:]
    else:
        self.uri = bits[1]

    parts = urlsplit(self.uri)
    self.path = parts.path or ""
    self.query = parts.query or ""
    self.fragment = parts.fragment or ""

    # Version
    match = VERSION_RE.match(bits[2])
    if match is None:
        raise InvalidHTTPVersion(bits[2])
    self.version = (int(match.group(1)), int(match.group(2)))


# Traceback (ValueError)
(tempenv-027621611529f) ~/.v/tempenv-701523535780 $ gunicorn w:f
[2015-05-09 11:53:50 -0400] [75550] [INFO] Starting gunicorn 19.3.0
[2015-05-09 11:53:50 -0400] [75550] [INFO] Listening at: http://127.0.0.1:8000 (75550)
[2015-05-09 11:53:50 -0400] [75550] [INFO] Using worker: sync
[2015-05-09 11:53:50 -0400] [75567] [INFO] Booting worker with pid: 75567
[2015-05-09 11:54:44 -0400] [75567] [ERROR] Error handling request
Traceback (most recent call last):
File "/Users/alex_gaynor/.virtualenvs/tempenv-027621611529f/lib/python2.7/site-packages/gunicorn/workers/sync.py", line 129, in handle
req = six.next(parser)
File "/Users/alex_gaynor/.virtualenvs/tempenv-027621611529f/lib/python2.7/site-packages/gunicorn/http/parser.py", line 41, in __next__
self.mesg = self.mesg_class(self.cfg, self.unreader, self.req_count)
File "/Users/alex_gaynor/.virtualenvs/tempenv-027621611529f/lib/python2.7/site-packages/gunicorn/http/message.py", line 153, in __init__
super(Request, self).__init__(cfg, unreader)
File "/Users/alex_gaynor/.virtualenvs/tempenv-027621611529f/lib/python2.7/site-packages/gunicorn/http/message.py", line 53, in __init__
unused = self.parse(self.unreader)
File "/Users/alex_gaynor/.virtualenvs/tempenv-027621611529f/lib/python2.7/site-packages/gunicorn/http/message.py", line 177, in parse
self.parse_request_line(bytes_to_str(line))
File "/Users/alex_gaynor/.virtualenvs/tempenv-027621611529f/lib/python2.7/site-packages/gunicorn/http/message.py", line 326, in parse_request_line
parts = urlsplit(self.uri)
File "/Users/alex_gaynor/.pyenv/versions/2.7.9/lib/python2.7/urlparse.py", line 214, in urlsplit
raise ValueError("Invalid IPv6 URL")
ValueError: Invalid IPv6 URL

# Fixed code
def parse_request_line(self, line):
    bits = line.split(None, 2)
    if len(bits) != 3:
        raise InvalidRequestLine(line)

    # Method
    if not METH_RE.match(bits[0]):
        raise InvalidRequestMethod(bits[0])
    self.method = bits[0].upper()

    # URI
    # When the path starts with //, urlsplit considers it as a
    # relative uri while the RDF says it shouldnt
    # http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2
    # considers it as an absolute url.
    # fix issue #297
    if bits[1].startswith("//"):
        self.uri = bits[1][1:]
    else:
        self.uri = bits[1]

    try:
        parts = urlsplit(self.uri)
    except ValueError:
        raise InvalidRequestLine(line)
    self.path = parts.path or ""
    self.query = parts.query or ""
    self.fragment = parts.fragment or ""

    # Version
    match = VERSION_RE.match(bits[2])
    if match is None:
        raise InvalidHTTPVersion(bits[2])
    self.version = (int(match.group(1)), int(match.group(2)))