rawgit
rawgit copied to clipboard
Should return a 404 for non-file (but file-like) URLs such as /:user/:repo/commit/*
Good chance it's something wrong that I've done here. Why is rawgit.com
redirecting to raw.githubusercontent.com
in this case?
❯❯❯ curl https://rawgit.com/ruby/ruby/commit/b3dbeb6e90f316584f70e33f6bfb9d83fa5f30d3.patch
<p>Moved Permanently. Redirecting to <a href="https://raw.githubusercontent.com/ruby/ruby/commit/b3dbeb6e90f316584f70e33f6bfb9d83fa5f30d3.patch">https://raw.githubusercontent.com/ruby/ruby/commit/b3dbeb6e90f316584f70e33f6bfb9d83fa5f30d3.patch</a></p>
❯❯❯ curl https://cdn.rawgit.com/ruby/ruby/commit/b3dbeb6e90f316584f70e33f6bfb9d83fa5f30d3.patch
404: Not Found
https://github.com/ruby/ruby/commit/b3dbeb6e90f316584f70e33f6bfb9d83fa5f30d3
There are several things happening here:
-
/ruby/ruby/commit/b3dbeb6e90f316584f70e33f6bfb9d83fa5f30d3.patch
doesn't actually point to a file in a repo, it points to a dynamic endpoint on GitHub that generates a patch file for a specific commit. RawGit only supports fetching actual repo files. -
Normally RawGit would just return a 404 for paths it doesn't support. But in this case the path actually looks like it could be a file path, so RawGit tries to process it as one.
-
.patch
isn't a whitelisted file extension, so rawgit.com assumes there's no benefit to proxying it and redirects you directly to GitHub to load it. But the redirect assumes the path is an actual repo file. raw.githubusercontent.com only knows how to handle repo files, so it returns a 404 because the path we're requesting is a dynamic endpoint, not a repo file. -
cdn.rawgit.com doesn't use the extension whitelist, so it just tries to load the file from GitHub. But once again, since the path doesn't point to an actual file, we get a 404.
tl;dr: RawGit only supports repo files, not dynamic GitHub endpoints, and ruby/ruby/commit/b3dbeb6e90f316584f70e33f6bfb9d83fa5f30d3.patch
isn't a repo file. Sorry.
We could do a better job of recognizing that /:user/:repo/commit/*
isn't a file URL though, so I'll leave this open as a bug.
Thanks for the explanation, Ryan. Gisting the patch first and then using RawGit with the gist worked just fine.