From b2e3ba180e8b354191ef2473d030d0fbd25d26c1 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 15:07:26 -0800 Subject: [PATCH 01/23] testing --- gradio/route_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index 6e663e5ff4b5b..8cb39967c4d4f 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -261,7 +261,7 @@ async def call_process_api( return output -def get_root_url(request: fastapi.Request) -> str: +def get_root_url(request: fastapi.Request, root_path: str | None) -> str: """ Gets the root url of the request, stripping off any query parameters and trailing slashes. Also ensures that the root url is https if the request is https. @@ -272,7 +272,7 @@ def get_root_url(request: fastapi.Request) -> str: root_url = str(root_url) if request.headers.get("x-forwarded-proto") == "https": root_url = root_url.replace("http://", "https://") - return root_url.rstrip("/") + return root_url.rstrip("/") + (root_path or "") def _user_safe_decode(src: bytes, codec: str) -> str: From 0c29f32795a7b395b13890e670d269c3036f5c19 Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Tue, 13 Feb 2024 23:08:30 +0000 Subject: [PATCH 02/23] add changeset --- .changeset/tricky-coins-sniff.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tricky-coins-sniff.md diff --git a/.changeset/tricky-coins-sniff.md b/.changeset/tricky-coins-sniff.md new file mode 100644 index 0000000000000..274523b1be761 --- /dev/null +++ b/.changeset/tricky-coins-sniff.md @@ -0,0 +1,5 @@ +--- +"gradio": minor +--- + +feat:[WIP] Set `root path` correctly From d23f835501f598b539d2894cbaada77ac0931e27 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 16:01:42 -0800 Subject: [PATCH 03/23] test --- gradio/route_utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index 8cb39967c4d4f..cfb8631fc03b7 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -261,7 +261,7 @@ async def call_process_api( return output -def get_root_url(request: fastapi.Request, root_path: str | None) -> str: +def get_root_url(request: fastapi.Request, route_path: str, root_path: str | None) -> str: """ Gets the root url of the request, stripping off any query parameters and trailing slashes. Also ensures that the root url is https if the request is https. @@ -272,6 +272,11 @@ def get_root_url(request: fastapi.Request, root_path: str | None) -> str: root_url = str(root_url) if request.headers.get("x-forwarded-proto") == "https": root_url = root_url.replace("http://", "https://") + root_url = root_url.rstrip("/") + route_path = route_path.rstrip("/") + if root_url.endswith(route_path): + root_url = root_url[: -len(route_path)] + route_path = route_path.rstrip("/") return root_url.rstrip("/") + (root_path or "") From e96ed9fb5cf47b5cd891e8f402215f23733a59d4 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 16:27:14 -0800 Subject: [PATCH 04/23] backend --- gradio/route_utils.py | 15 ++++++++------- gradio/routes.py | 16 ++++++++++++---- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index cfb8631fc03b7..48265c88b4471 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -261,23 +261,24 @@ async def call_process_api( return output -def get_root_url(request: fastapi.Request, route_path: str, root_path: str | None) -> str: +def get_root_url( + request: fastapi.Request, route_path: str, root_path: str | None +) -> str: """ - Gets the root url of the request, stripping off any query parameters and trailing slashes. - Also ensures that the root url is https if the request is https. + Gets the root url of the request, stripping off any query parameters, the route_path, and trailing slashes. + Also ensures that the root url is https if the request is https. If root_path is provided, it is appended to the root url. + The final root url will not have a trailing slash. """ root_url = str(request.url) root_url = httpx.URL(root_url) root_url = root_url.copy_with(query=None) - root_url = str(root_url) + root_url = str(root_url).rstrip("/") if request.headers.get("x-forwarded-proto") == "https": root_url = root_url.replace("http://", "https://") - root_url = root_url.rstrip("/") route_path = route_path.rstrip("/") if root_url.endswith(route_path): root_url = root_url[: -len(route_path)] - route_path = route_path.rstrip("/") - return root_url.rstrip("/") + (root_path or "") + return (root_url.rstrip("/") + (root_path or "")).rstrip("/") def _user_safe_decode(src: bytes, codec: str) -> str: diff --git a/gradio/routes.py b/gradio/routes.py index 45af1a2bb644a..240aeb45117e1 100644 --- a/gradio/routes.py +++ b/gradio/routes.py @@ -311,7 +311,9 @@ def login(form_data: OAuth2PasswordRequestForm = Depends()): def main(request: fastapi.Request, user: str = Depends(get_current_user)): mimetypes.add_type("application/javascript", ".js") blocks = app.get_blocks() - root_path = route_utils.get_root_url(request) + root_path = route_utils.get_root_url( + request=request, route_path="/", root_path=app.root_path + ) if app.auth is None or user is not None: config = copy.deepcopy(app.get_blocks().config) config["root"] = root_path @@ -353,7 +355,9 @@ def api_info(): @app.get("/config", dependencies=[Depends(login_check)]) def get_config(request: fastapi.Request): config = copy.deepcopy(app.get_blocks().config) - root_path = route_utils.get_root_url(request)[: -len("/config")] + root_path = route_utils.get_root_url( + request=request, route_path="/config", root_path=app.root_path + ) config["root"] = root_path config = add_root_url(config, root_path) return config @@ -570,7 +574,9 @@ async def predict( content={"error": str(error) if show_error else None}, status_code=500, ) - root_path = route_utils.get_root_url(request)[: -len(f"/api/{api_name}")] + root_path = route_utils.get_root_url( + request=request, route_path=f"/api/{api_name}", root_path=app.root_path + ) output = add_root_url(output, root_path) return output @@ -580,7 +586,9 @@ async def queue_data( session_hash: str, ): blocks = app.get_blocks() - root_path = route_utils.get_root_url(request)[: -len("/queue/data")] + root_path = route_utils.get_root_url( + request=request, route_path="/queue/data", root_path=app.root_path + ) async def sse_stream(request: fastapi.Request): try: From 8d979f0992fc1f2bba89580e8508a589860b1a8a Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 16:34:57 -0800 Subject: [PATCH 05/23] fix --- gradio/route_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index 48265c88b4471..30089f75acba7 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -276,7 +276,7 @@ def get_root_url( if request.headers.get("x-forwarded-proto") == "https": root_url = root_url.replace("http://", "https://") route_path = route_path.rstrip("/") - if root_url.endswith(route_path): + if root_url.endswith(route_path) and len(route_path) > 0: root_url = root_url[: -len(route_path)] return (root_url.rstrip("/") + (root_path or "")).rstrip("/") From 866045301e0b8defba8f08a6f544eb361ca2181d Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 16:46:18 -0800 Subject: [PATCH 06/23] add unit tests --- test/test_routes.py | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/test_routes.py b/test/test_routes.py index d6cf76bc7c670..8f7d4c66f5134 100644 --- a/test/test_routes.py +++ b/test/test_routes.py @@ -10,7 +10,7 @@ import pandas as pd import pytest import starlette.routing -from fastapi import FastAPI +from fastapi import FastAPI, Request from fastapi.testclient import TestClient from gradio_client import media_data @@ -25,7 +25,7 @@ routes, wasm_utils, ) -from gradio.route_utils import FnIndexInferError +from gradio.route_utils import FnIndexInferError, get_root_url @pytest.fixture() @@ -862,3 +862,40 @@ def test_component_server_endpoints(connect): }, ) assert fail_req.status_code == 404 + + +@pytest.mark.parametrize( + "request_url, route_path, root_path, expected_root_url", + [ + ("http://localhost:7860/", "/", None, "http://localhost:7860"), + ("http://localhost:7860/demo/test", "/demo/test", None, "http://localhost:7860"), + ("http://localhost:7860/demo/test/", "/demo/test", None, "http://localhost:7860"), + ( + "http://localhost:7860/demo/test?query=1", + "/demo/test", + None, + "http://localhost:7860", + ), + ( + "http://localhost:7860/demo/test?query=1", + "/demo/test", + "/gradio", + "http://localhost:7860/gradio", + ), + ( + "http://localhost:7860/demo/test?query=1", + "/demo/test", + "/gradio/", + "http://localhost:7860/gradio", + ), + ( + "https://localhost:7860/demo/test?query=1", + "/demo/test", + "/gradio/", + "https://localhost:7860/gradio", + ), + ], +) +def test_get_root_url(request_url, route_path, root_path, expected_root_url): + request = Request({"path": request_url, "type": "http", "headers": {}}) + assert get_root_url(request, route_path, root_path) == expected_root_url From 29c575bca5f695516728f68526e9f43cac4a5aa5 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 16:54:01 -0800 Subject: [PATCH 07/23] testing --- gradio/route_utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index 30089f75acba7..e882be96140b1 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -269,6 +269,7 @@ def get_root_url( Also ensures that the root url is https if the request is https. If root_path is provided, it is appended to the root url. The final root url will not have a trailing slash. """ + print("params", request.url, route_path, root_path) root_url = str(request.url) root_url = httpx.URL(root_url) root_url = root_url.copy_with(query=None) From f0bbdc42143c65df45a13250d02576e40e3501ef Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 16:55:13 -0800 Subject: [PATCH 08/23] remove check --- gradio/route_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index e882be96140b1..8db21a4b7b98d 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -277,7 +277,7 @@ def get_root_url( if request.headers.get("x-forwarded-proto") == "https": root_url = root_url.replace("http://", "https://") route_path = route_path.rstrip("/") - if root_url.endswith(route_path) and len(route_path) > 0: + if len(route_path) > 0: root_url = root_url[: -len(route_path)] return (root_url.rstrip("/") + (root_path or "")).rstrip("/") From 3e1083d40432e625bde21d3dd7712d1c9e6ca2db Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Wed, 14 Feb 2024 01:06:13 +0000 Subject: [PATCH 09/23] add changeset --- .changeset/tricky-coins-sniff.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/tricky-coins-sniff.md b/.changeset/tricky-coins-sniff.md index 274523b1be761..cd65ed4e137d0 100644 --- a/.changeset/tricky-coins-sniff.md +++ b/.changeset/tricky-coins-sniff.md @@ -2,4 +2,4 @@ "gradio": minor --- -feat:[WIP] Set `root path` correctly +feat:Set `root` correctly for Gradio apps that are deployed behind reverse proxies From 71d52833b4e7e2c4faa50ddd840c3d1c6513482c Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 17:25:09 -0800 Subject: [PATCH 10/23] trying something --- gradio/route_utils.py | 5 +++-- js/app/src/Index.svelte | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index 8db21a4b7b98d..d2b8e06ce88a5 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -274,8 +274,9 @@ def get_root_url( root_url = httpx.URL(root_url) root_url = root_url.copy_with(query=None) root_url = str(root_url).rstrip("/") - if request.headers.get("x-forwarded-proto") == "https": - root_url = root_url.replace("http://", "https://") + # if request.headers.get("x-forwarded-proto") == "https": + # root_url = root_url.replace("http://", "https://") + root_url = root_url.replace("https://", "http://") route_path = route_path.rstrip("/") if len(route_path) > 0: root_url = root_url[: -len(route_path)] diff --git a/js/app/src/Index.svelte b/js/app/src/Index.svelte index 6aae52a817e79..31388813ff6a7 100644 --- a/js/app/src/Index.svelte +++ b/js/app/src/Index.svelte @@ -255,6 +255,9 @@ status_callback: handle_status }); config = app.config; + if (window.location.protocol === "https:") { + config.root = config.root.replace("http://", "https://"); + } window.__gradio_space__ = config.space_id; status = { From c28abee409dc3e8a455e4a684be9d5a4bbabd1c6 Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Wed, 14 Feb 2024 01:26:03 +0000 Subject: [PATCH 11/23] add changeset --- .changeset/tricky-coins-sniff.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/tricky-coins-sniff.md b/.changeset/tricky-coins-sniff.md index cd65ed4e137d0..fdc4f878f1172 100644 --- a/.changeset/tricky-coins-sniff.md +++ b/.changeset/tricky-coins-sniff.md @@ -1,4 +1,5 @@ --- +"@gradio/app": minor "gradio": minor --- From b80d18e71f407d103d8c2f11da84bfad4ba2a2de Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 17:34:53 -0800 Subject: [PATCH 12/23] override --- client/js/src/client.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/js/src/client.ts b/client/js/src/client.ts index 41516ed48bfa5..abadce9945470 100644 --- a/client/js/src/client.ts +++ b/client/js/src/client.ts @@ -301,6 +301,9 @@ export function api_factory( async function config_success(_config: Config): Promise { config = _config; + if (window.location.protocol === "https://") { + config.root = config.root.replace("http://", "https://"); + } api_map = map_names_to_ids(_config?.dependencies || []); if (config.auth_required) { return { From 74e3f2bb600a2c45d9d0d02b1c50ee568258eced Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Wed, 14 Feb 2024 01:35:46 +0000 Subject: [PATCH 13/23] add changeset --- .changeset/tricky-coins-sniff.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/tricky-coins-sniff.md b/.changeset/tricky-coins-sniff.md index fdc4f878f1172..3ab2326d3e256 100644 --- a/.changeset/tricky-coins-sniff.md +++ b/.changeset/tricky-coins-sniff.md @@ -1,5 +1,6 @@ --- "@gradio/app": minor +"@gradio/client": minor "gradio": minor --- From 4c8e7f781730156f120f08bdc8ea601733e47aa8 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 17:43:05 -0800 Subject: [PATCH 14/23] fix --- client/js/src/client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/js/src/client.ts b/client/js/src/client.ts index abadce9945470..a6e4a27baa9bb 100644 --- a/client/js/src/client.ts +++ b/client/js/src/client.ts @@ -301,7 +301,7 @@ export function api_factory( async function config_success(_config: Config): Promise { config = _config; - if (window.location.protocol === "https://") { + if (window.location.protocol === "https:") { config.root = config.root.replace("http://", "https://"); } api_map = map_names_to_ids(_config?.dependencies || []); @@ -312,6 +312,7 @@ export function api_factory( }; } try { + console.log("root", config.root, ) api = await view_api(config); } catch (e) { console.error(`Could not get api details: ${e.message}`); From 5f26128d7cfd6e033e608c0b4a9840cfaf8a7944 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 17:43:20 -0800 Subject: [PATCH 15/23] fix --- client/js/src/client.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/js/src/client.ts b/client/js/src/client.ts index a6e4a27baa9bb..667132ea535eb 100644 --- a/client/js/src/client.ts +++ b/client/js/src/client.ts @@ -312,7 +312,7 @@ export function api_factory( }; } try { - console.log("root", config.root, ) + console.log("root", config.root, window.location.protocol); api = await view_api(config); } catch (e) { console.error(`Could not get api details: ${e.message}`); From 3e507d1d760fd38f43b8effbfa0038bd0888dabb Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 17:50:23 -0800 Subject: [PATCH 16/23] clean --- client/js/src/client.ts | 1 - gradio/route_utils.py | 1 - 2 files changed, 2 deletions(-) diff --git a/client/js/src/client.ts b/client/js/src/client.ts index 667132ea535eb..2fb161c055f0a 100644 --- a/client/js/src/client.ts +++ b/client/js/src/client.ts @@ -312,7 +312,6 @@ export function api_factory( }; } try { - console.log("root", config.root, window.location.protocol); api = await view_api(config); } catch (e) { console.error(`Could not get api details: ${e.message}`); diff --git a/gradio/route_utils.py b/gradio/route_utils.py index d2b8e06ce88a5..da2a2f9af4e52 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -269,7 +269,6 @@ def get_root_url( Also ensures that the root url is https if the request is https. If root_path is provided, it is appended to the root url. The final root url will not have a trailing slash. """ - print("params", request.url, route_path, root_path) root_url = str(request.url) root_url = httpx.URL(root_url) root_url = root_url.copy_with(query=None) From 1fcb37370ad42d507dbbfec42b6bb1b4ec047c8f Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 17:51:01 -0800 Subject: [PATCH 17/23] lint --- test/test_routes.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/test/test_routes.py b/test/test_routes.py index 8f7d4c66f5134..86e81f4e1537a 100644 --- a/test/test_routes.py +++ b/test/test_routes.py @@ -868,8 +868,18 @@ def test_component_server_endpoints(connect): "request_url, route_path, root_path, expected_root_url", [ ("http://localhost:7860/", "/", None, "http://localhost:7860"), - ("http://localhost:7860/demo/test", "/demo/test", None, "http://localhost:7860"), - ("http://localhost:7860/demo/test/", "/demo/test", None, "http://localhost:7860"), + ( + "http://localhost:7860/demo/test", + "/demo/test", + None, + "http://localhost:7860", + ), + ( + "http://localhost:7860/demo/test/", + "/demo/test", + None, + "http://localhost:7860", + ), ( "http://localhost:7860/demo/test?query=1", "/demo/test", From a0cdefc5e42a6ede10c98a4558f096e391fd7c0b Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Tue, 13 Feb 2024 17:52:33 -0800 Subject: [PATCH 18/23] route utils --- gradio/route_utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index da2a2f9af4e52..bceda289f0a8a 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -273,9 +273,8 @@ def get_root_url( root_url = httpx.URL(root_url) root_url = root_url.copy_with(query=None) root_url = str(root_url).rstrip("/") - # if request.headers.get("x-forwarded-proto") == "https": - # root_url = root_url.replace("http://", "https://") - root_url = root_url.replace("https://", "http://") + if request.headers.get("x-forwarded-proto") == "https": + root_url = root_url.replace("http://", "https://") route_path = route_path.rstrip("/") if len(route_path) > 0: root_url = root_url[: -len(route_path)] From 9b8810ff9af4d9a50032752af09cefcf2ef7a7ac Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Wed, 14 Feb 2024 01:53:36 +0000 Subject: [PATCH 19/23] add changeset --- .changeset/tricky-coins-sniff.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.changeset/tricky-coins-sniff.md b/.changeset/tricky-coins-sniff.md index 3ab2326d3e256..936703f4eaf60 100644 --- a/.changeset/tricky-coins-sniff.md +++ b/.changeset/tricky-coins-sniff.md @@ -1,7 +1,7 @@ --- -"@gradio/app": minor -"@gradio/client": minor -"gradio": minor +"@gradio/app": patch +"@gradio/client": patch +"gradio": patch --- -feat:Set `root` correctly for Gradio apps that are deployed behind reverse proxies +fix:Set `root` correctly for Gradio apps that are deployed behind reverse proxies From 060dfd569aba9be18ec51e88ee2dbd47ba39a161 Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Wed, 14 Feb 2024 07:53:46 -0800 Subject: [PATCH 20/23] changes --- js/app/src/Index.svelte | 3 --- 1 file changed, 3 deletions(-) diff --git a/js/app/src/Index.svelte b/js/app/src/Index.svelte index 31388813ff6a7..6aae52a817e79 100644 --- a/js/app/src/Index.svelte +++ b/js/app/src/Index.svelte @@ -255,9 +255,6 @@ status_callback: handle_status }); config = app.config; - if (window.location.protocol === "https:") { - config.root = config.root.replace("http://", "https://"); - } window.__gradio_space__ = config.space_id; status = { From a7b8ea8b0ff68ad252b8105d5f146b7adecf9acb Mon Sep 17 00:00:00 2001 From: gradio-pr-bot Date: Wed, 14 Feb 2024 15:54:32 +0000 Subject: [PATCH 21/23] add changeset --- .changeset/tricky-coins-sniff.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.changeset/tricky-coins-sniff.md b/.changeset/tricky-coins-sniff.md index 936703f4eaf60..da3879ece93d3 100644 --- a/.changeset/tricky-coins-sniff.md +++ b/.changeset/tricky-coins-sniff.md @@ -1,5 +1,4 @@ --- -"@gradio/app": patch "@gradio/client": patch "gradio": patch --- From 73820312049fc79242564a80c718f2c952a30a1b Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Wed, 14 Feb 2024 07:58:49 -0800 Subject: [PATCH 22/23] test --- gradio/route_utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index bceda289f0a8a..47281a46fca6d 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -273,8 +273,9 @@ def get_root_url( root_url = httpx.URL(root_url) root_url = root_url.copy_with(query=None) root_url = str(root_url).rstrip("/") - if request.headers.get("x-forwarded-proto") == "https": - root_url = root_url.replace("http://", "https://") + # if request.headers.get("x-forwarded-proto") == "https": + # root_url = root_url.replace("http://", "https://") + root_url = root_url.replace("https://", "http://") route_path = route_path.rstrip("/") if len(route_path) > 0: root_url = root_url[: -len(route_path)] From 335daba3999f0c478ae2d62cfa051be8a170476d Mon Sep 17 00:00:00 2001 From: Abubakar Abid Date: Wed, 14 Feb 2024 08:07:29 -0800 Subject: [PATCH 23/23] revert testing --- gradio/route_utils.py | 5 ++--- test/test_routes.py | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/gradio/route_utils.py b/gradio/route_utils.py index 47281a46fca6d..bceda289f0a8a 100644 --- a/gradio/route_utils.py +++ b/gradio/route_utils.py @@ -273,9 +273,8 @@ def get_root_url( root_url = httpx.URL(root_url) root_url = root_url.copy_with(query=None) root_url = str(root_url).rstrip("/") - # if request.headers.get("x-forwarded-proto") == "https": - # root_url = root_url.replace("http://", "https://") - root_url = root_url.replace("https://", "http://") + if request.headers.get("x-forwarded-proto") == "https": + root_url = root_url.replace("http://", "https://") route_path = route_path.rstrip("/") if len(route_path) > 0: root_url = root_url[: -len(route_path)] diff --git a/test/test_routes.py b/test/test_routes.py index 86e81f4e1537a..84a3e1a5c907b 100644 --- a/test/test_routes.py +++ b/test/test_routes.py @@ -888,8 +888,8 @@ def test_component_server_endpoints(connect): ), ( "http://localhost:7860/demo/test?query=1", - "/demo/test", - "/gradio", + "/demo/test/", + "/gradio/", "http://localhost:7860/gradio", ), (