[Blueprints] Translate GitHub.com file URLs into CORS-accessible raw.githubusercontent.com #1810
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Translates GitHub URLs into raw.githubusercontent.com URLs.
For example:
Would be interepreted as
Motivation
There's virtually a zero chance you actually want to refer to the HTML response served
by GitHub.com, with the GitHub UI, file preview, etc. in it. Almost certainly, you want
to download the raw file.
This often confuses Blueprint authors when the GitHub URL they've used in their Blueprint
does not work. There's plenty of issues in the Playground repository asking specifically
about that. Well, GitHub.com response is not what they want, and even if it was, GitHub
does not provide the necessary CORS headers.
While the URL rewriting might confuse advanced developers, they're in a good
position to figure it out. This feature shouldn't do any harm.
Note the rewriting is implemented in UrlResource, which is used in all Playground
implementations, e.g. the browser, the CLI, Studio, etc. While most of them don't
need to worry about CORS, we still want to make sure the same Blueprints will work
in all Playground runtimes.
Testing instructions
Confirm all CI checks pass
Caveats
Directory URLs are not supported. For example, a URL such as
Would be rewritten to
Which yields just
404: Not Found
. I think that's fine. At least the error communicates more than just "missing CORS headers".There's no way to distinguish between a file and a directory based just on its GitHub.com
URL. If this starts coming up a lot in Playground issues, let's explore consulting the
repository contents and rewriting the URL resource as a git directory resource.
@see #1793
cc @akirk @dmsnell