def process_headers(self, headers): for name, value in headers: if not isinstance(name, string_types): raise TypeError('%r is not a string' % name) if HEADER_RE.search(name): raise InvalidHeaderName('%r' % name) if HEADER_VALUE_RE.search(value): raise InvalidHeader('%r' % value) value = str(value).strip() lname = name.lower().strip() if lname == "content-length": self.response_length = int(value) elif util.is_hoppish(name): if lname == "connection": # handle websocket if value.lower().strip() == "upgrade": self.upgrade = True elif lname == "upgrade": if value.lower().strip() == "websocket": self.headers.append((name.strip(), value)) # ignore hopbyhop headers continue self.headers.append((name.strip(), value))