rawgit icon indicating copy to clipboard operation
rawgit copied to clipboard

Should return a 404 for non-file (but file-like) URLs such as /:user/:repo/commit/*

Open sjackman opened this issue 6 years ago • 2 comments

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

sjackman avatar Apr 30 '18 05:04 sjackman

There are several things happening here:

  1. /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.

  2. 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.

  3. .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.

  4. 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.

rgrove avatar Apr 30 '18 21:04 rgrove

Thanks for the explanation, Ryan. Gisting the patch first and then using RawGit with the gist worked just fine.

sjackman avatar Apr 30 '18 22:04 sjackman