Esempio n. 1
0
def meta(environ, start_response):
    path = environ["PATH_INFO"]
    start_response("200 OK", {})
    if path.startswith("/meta/version"):
        return [str(__version__)]
    elif path.startswith("/meta/backend"):
        return [str(os.environ.get("DOTCLOUD_SERVER_BACKEND_PORT", Tunnel.backend_port))]
    elif path.startswith("/meta/metrics"):
        return [json.dumps(metrics.dump_metrics(), sort_keys=True, indent=2, separators=(",", ": "))]
Esempio n. 2
0
def meta(environ, start_response):
    path = environ['PATH_INFO']
    start_response('200 OK', {})
    if path.startswith('/meta/version'):
        return [str(__version__)]
    elif path.startswith('/meta/backend'):
        return [str(os.environ.get('DOTCLOUD_SERVER_BACKEND_PORT', 
            Tunnel.backend_port))]
    elif path.startswith('/meta/metrics'):
        return [json.dumps(metrics.dump_metrics(),
            sort_keys=True, indent=2, separators=(',', ': '))]
Esempio n. 3
0
def connection_handler(socket, address):
    host = peek_http_host(socket)
    hostname = host.split(':')[0]
    if not hostname:
        logging.debug("!no hostname, closing")
        socket.close()
        return

    if hostname.startswith('_version.'):
        send_http_response(socket, __version__)
        socket.close()
        logging.debug("version request from {0}".format(address[0]))
        return

    if hostname.startswith('_backend.'):
        port = os.environ.get('DOTCLOUD_SERVER_BACKEND_PORT',
                              Tunnel.backend_port)
        send_http_response(socket, port)
        socket.close()
        return

    if hostname.startswith('_metrics.'):
        content = json.dumps(metrics.dump_metrics(),
                             sort_keys=True,
                             indent=2,
                             separators=(',', ': '))
        send_http_response(socket, content)
        socket.close()
        logging.debug("metrics request from {0}".format(address[0]))
        return

    tunnel = Tunnel.get_by_hostname(hostname)
    if not tunnel:
        logging.debug("!no tunnel, closing ({0})".format(hostname))
        socket.close()
        return

    conn, proxy_used = tunnel.pop_proxy_conn(timeout=2)
    if not conn:
        logging.debug("!no proxy connection, closing")
        socket.close()
        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()
Esempio n. 4
0
def connection_handler(socket, address):
    host = peek_http_host(socket)
    hostname = host.split(':')[0]
    if not hostname:
        logging.debug("!no hostname, closing")
        socket.close()
        return

    if hostname.startswith('_version.'):
        send_http_response(socket, __version__)
        socket.close()
        logging.debug("version request from {0}".format(address[0]))
        return

    if hostname.startswith('_backend.'):
        port = os.environ.get('DOTCLOUD_SERVER_BACKEND_PORT', 
                    Tunnel.backend_port)
        send_http_response(socket, port)
        socket.close()
        return

    if hostname.startswith('_metrics.'):
        content = json.dumps(metrics.dump_metrics(),
                    sort_keys=True, indent=2, separators=(',', ': '))
        send_http_response(socket, content)
        socket.close()
        logging.debug("metrics request from {0}".format(address[0]))
        return

    tunnel = Tunnel.get_by_hostname(hostname)
    if not tunnel:
        logging.debug("!no tunnel, closing ({0})".format(
            hostname))
        socket.close()
        return

    conn, proxy_used = tunnel.pop_proxy_conn(timeout=2)
    if not conn:
        logging.debug("!no proxy connection, closing")
        socket.close()
        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()
Esempio n. 5
0
def meta(environ, start_response):
    path = environ['PATH_INFO']
    start_response('200 OK', {})
    if path.startswith('/meta/version'):
        return [str(__version__)]
    elif path.startswith('/meta/backend'):
        return [
            str(
                os.environ.get('DOTCLOUD_SERVER_BACKEND_PORT',
                               Tunnel.backend_port))
        ]
    elif path.startswith('/meta/metrics'):
        return [
            json.dumps(metrics.dump_metrics(),
                       sort_keys=True,
                       indent=2,
                       separators=(',', ': '))
        ]