Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use x-forwarded-host header to determine the root url, and let users provide a full root_path to override the automatically determined root url #7641

Merged
merged 9 commits into from Mar 8, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Mar 8, 2024

This PR fixes the issue that we're seeing where Gradio apps don't render properly on k8 environments and some other places where the URL of the Gradio app is behind an app router or proxy.

The fix is to look at the x-forwarded-host header, if available, and use that in place of the request URL, as this header points to the public URL of the Gradio app.

In addition, we provide users with a fallback in case Gradio is not able to determine the root url automatically. By providing a full root_path (either as an env variable or as a parameter in launch()), users can set their own root url, which takes precedence over the one Gradio constructs automatically.

Closes: #7317

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Mar 8, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/3f6ced361dfac11fe1545fb16ae643f1e93e0af1/gradio-4.20.1-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@3f6ced361dfac11fe1545fb16ae643f1e93e0af1#subdirectory=client/python"

@gradio-pr-bot
Copy link
Contributor

gradio-pr-bot commented Mar 8, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio patch
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

Use x-forwarded-host header to determine the root url, and let users provide a full root_path to override the automatically determined root url

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs abidlabs marked this pull request as ready for review March 8, 2024 16:11
@abidlabs abidlabs changed the title debug proxy header Use x-forwarded-host header, and let users provide a full root_url to override the automatically determined root url Mar 8, 2024
@abidlabs abidlabs changed the title Use x-forwarded-host header, and let users provide a full root_url to override the automatically determined root url Use x-forwarded-host header to determine the root url, and let users provide a full root_path to override the automatically determined root url Mar 8, 2024
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix @abidlabs !

@abidlabs
Copy link
Member Author

abidlabs commented Mar 8, 2024

Thanks a bunch for the review @freddyaboulton

@abidlabs abidlabs merged commit cb3999e into main Mar 8, 2024
8 checks passed
@abidlabs abidlabs deleted the proxy-header branch March 8, 2024 18:15
@pngwn pngwn mentioned this pull request Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Gradio static files do not follow the root_path behind a Jupyter proxy on k8s
3 participants