Skip to content

Commit

Permalink
SSR Safari Fix (#9958)
Browse files Browse the repository at this point in the history
* fix

* add changeset

* fix

* fix

* fix

* update

* fix chrome

* move logic

* format

* fixes

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
dawoodkhan82 and gradio-pr-bot authored Nov 15, 2024
1 parent 74b4ff0 commit 75ad3e3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/hot-ghosts-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gradio": patch
---

fix:SSR Safari Fix
24 changes: 22 additions & 2 deletions gradio/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,31 @@ async def proxy_to_node(
request.method, httpx.URL(url), headers=headers
)
node_response = await App.client.send(new_request)
content = node_response.content
user_agent = request.headers.get("user-agent", "").lower()
is_safari = (
"safari" in user_agent
and "chrome" not in user_agent
and "chromium" not in user_agent
)
response_headers = {}
if is_safari:
response_headers = {
"Access-Control-Allow-Origin": "*",
"Cross-Origin-Opener-Policy": "same-origin",
"Cross-Origin-Embedder-Policy": "require-corp",
}
if request.url.path.endswith(".js"):
response_headers["Content-Type"] = (
"application/javascript; charset=utf-8"
)
elif request.url.path.endswith(".css"):
response_headers["Content-Type"] = "text/css; charset=utf-8"

return Response(
content=node_response.content,
content=content,
status_code=node_response.status_code,
headers=dict(node_response.headers),
headers=response_headers if is_safari else node_response.headers,
)

def configure_app(self, blocks: gradio.Blocks) -> None:
Expand Down

0 comments on commit 75ad3e3

Please sign in to comment.