def serverconnect(self, server_conn): hostname = server_conn.address.host # TODO (NOT FOR ALL SITE, BUT NEEDED FOR YOUTUBE) server_conn.sni = "" server_conn.cachebrowsed = False server_conn.cdn = None server_conn.cb_status_message = "" try: host = Host.get_or_bootstrap(hostname=hostname) except DoesNotExist: err = "Bootstrapping host {} failed".format(hostname) server_conn.cb_status_message = err return server_conn # Skip if host is not active if not host.is_active: server_conn.status = "Host not active" return server_conn cdn = host.cdn if not cdn.valid or not cdn.edge_server: err = "Host {} does not have a valid CDN".format(hostname) server_conn.cb_status_message = err return server_conn server_conn.address = Address((cdn.edge_server, server_conn.address.port)) server_conn.sni = "" server_conn.cachebrowsed = True server_conn.cdn = {"id": cdn.id, "name": cdn.name} return server_conn
def request(self, flow): flow._id = self._id_counter self._id_counter += 1 flow.request.scheme_upgraded = False flow.request.headers["host"] = flow.request.pretty_host if flow.request.scheme == "http": try: host = Host.get_or_bootstrap(hostname=flow.request.host) if host.is_active and host.ssl: flow.request.scheme = "https" flow.request.port = 443 flow.request.scheme_upgraded = True except DoesNotExist: pass self.publish_flow(flow) return flow