mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-06 12:30:29 +08:00
SSR Safari Fix (#9958)
* 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>
This commit is contained in:
parent
74b4ff0e61
commit
75ad3e3419
5
.changeset/hot-ghosts-crash.md
Normal file
5
.changeset/hot-ghosts-crash.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:SSR Safari Fix
|
@ -274,11 +274,31 @@ class App(FastAPI):
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user