def split_request_uri(uri): if uri.startswith("//"): # When the path starts with //, urlsplit considers it as a # relative uri while the RFC says we should consider it as abs_path # http://www.w3.org/Protocols/rfc2616/rfc2616-sec5.html#sec5.1.2 # We use temporary dot prefix to workaround this behaviour parts = _compat.urlsplit("." + uri) return parts._replace(path=parts.path[1:]) return _compat.urlsplit(uri)
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)))