def connection_handler(socket, address): hostname = peek_http_host(socket) if not hostname: send_http_error(socket, 'No hostname', '400 Bad Request') return if hostname == Tunnel.domain_suffix: meta.server.process_request((socket, address)) return tunnel = Tunnel.get_by_hostname(hostname) if not tunnel: send_http_error(socket, 'No tunnel for {0}'.format(hostname), '410 Gone') return conn, proxy_used = tunnel.pop_proxy_conn(timeout=2) if not conn: send_http_error(socket, 'No proxy connections', '502 Bad Gateway') return protocol.send_message(conn, protocol.proxy_reply()) pool = util.join_sockets(conn, socket) proxy_used.send(pool) logging.debug("popped connection:\"{0}\" for frontend:\"{1}\"".format( tunnel.name, hostname)) pool.waitall()
def connection_handler(socket, address): hostname = peek_http_host(socket) if not hostname: send_http_error(socket, "No hostname", "400 Bad Request") return if hostname == Tunnel.domain_suffix: meta.server.process_request((socket, address)) return tunnel = Tunnel.get_by_hostname(hostname) if not tunnel: send_http_error(socket, "No tunnel for {0}".format(hostname), "410 Gone") return conn, proxy_used = tunnel.pop_proxy_conn(timeout=2) if not conn: send_http_error(socket, "No proxy connections", "502 Bad Gateway") return protocol.send_message(conn, protocol.proxy_reply()) pool = util.join_sockets(conn, socket) proxy_used.send(pool) logging.debug('popped connection:"{0}" for frontend:"{1}"'.format(tunnel.name, hostname)) pool.waitall()
def _test(self, header, expected): actual = peek_http_host(Socket(header)) self.assertEqual(actual, expected)