def set_default_headers(self): if config.get_option("server.enableXsrfProtection"): self.set_header("Access-Control-Allow-Headers", "X-Xsrftoken") self.set_header( "Access-Control-Allow-Origin", Report.get_url(config.get_option("browser.serverAddress")), ) self.set_header("Vary", "Origin") self.set_header("Access-Control-Allow-Credentials", "true") elif routes.allow_cross_origin_requests(): self.set_header("Access-Control-Allow-Origin", "*")
def test_get_url(self, baseUrl, port, expected_url): options = {"server.headless": False, "global.developmentMode": False} if baseUrl: options["server.baseUrlPath"] = baseUrl if port: options["server.port"] = port mock_get_option = testutil.build_mock_config_get_option(options) with patch.object(config, "get_option", new=mock_get_option): actual_url = Report.get_url("the_ip_address") self.assertEqual(expected_url, actual_url)
def _print_url(is_running_hello: bool) -> None: if is_running_hello: title_message = "Welcome to Streamlit. Check out our demo in your browser." else: title_message = "You can now view your Streamlit app in your browser." named_urls = [] if config.is_manually_set("browser.serverAddress"): named_urls = [ ("URL", Report.get_url(config.get_option("browser.serverAddress"))) ] elif ( config.is_manually_set("server.address") and not server_address_is_unix_socket() ): named_urls = [ ("URL", Report.get_url(config.get_option("server.address"))), ] elif config.get_option("server.headless"): internal_ip = net_util.get_internal_ip() if internal_ip: named_urls.append(("Network URL", Report.get_url(internal_ip))) external_ip = net_util.get_external_ip() if external_ip: named_urls.append(("External URL", Report.get_url(external_ip))) else: named_urls = [ ("Local URL", Report.get_url("localhost")), ] internal_ip = net_util.get_internal_ip() if internal_ip: named_urls.append(("Network URL", Report.get_url(internal_ip))) click.secho("") click.secho(" %s" % title_message, fg="blue", bold=True) click.secho("") for url_name, url in named_urls: url_util.print_url(url_name, url) click.secho("") if is_running_hello: click.secho(" Ready to create your own Python apps super quickly?") click.secho(" Head over to ", nl=False) click.secho("https://docs.streamlit.io", bold=True) click.secho("") click.secho(" May you create awesome apps!") click.secho("") click.secho("")
def maybe_open_browser(): if config.get_option("server.headless"): # Don't open browser when in headless mode. return if server.browser_is_connected: # Don't auto-open browser if there's already a browser connected. # This can happen if there's an old tab repeatedly trying to # connect, and it happens to success before we launch the browser. return if config.is_manually_set("browser.serverAddress"): addr = config.get_option("browser.serverAddress") elif config.is_manually_set("server.address"): addr = config.get_option("server.address") else: addr = "localhost" util.open_browser(Report.get_url(addr))