Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

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

Open
sjackman opened this issue Apr 30, 2018 · 2 comments
Labels

Comments

@sjackman
Copy link

sjackman commented Apr 30, 2018

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

ruby/ruby@b3dbeb6

@rgrove
Copy link
Owner

rgrove commented Apr 30, 2018

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 rgrove changed the title Rawgit redirects to raw.githubusercontent.com Should return a 404 for non-file (but file-like) URLs such as /:user/:repo/commit/* Apr 30, 2018
@rgrove rgrove added the bug label Apr 30, 2018
@sjackman
Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants