This is a quick and dirty trick to get all HTTPS local connections to raw.githubusercontent.com being redirected to RawGit CDN (https://cdn.rawgit.com).
By using this hack, you can fool your applications into connecting to RawGit every time they try to connect to raw.githubusercontent.com.
Of course, this implies that you trust RawGit to the same degree as GitHub to serve the contents.
The trick relies on a local Python script issuing HTTP redirects.
These instructions are for GNU/Linux (but the same idea may be easily ported to other platforms).
Add the following line to /etc/hosts (of course, you must be root - or use sudo):
127.0.0.1 raw.githubusercontent.com
Generate a self-signed certificate for raw.githubusercontent.com:
openssl req -x509 -newkey rsa:2048 -keyout ghrkey.pem -out ghrcert.crt -days 900 -subj '/CN=raw.githubusercontent.com/O=MyCompany/C=US' -nodes
Mark the self-signed certificate as a trusted CA certificate:
sudo cp ghrcert.crt /usr/local/share/ca-certificates/ sudo update-ca-certificates
NOTE: this is fine for Debian 9, other GNU/Linux distributions may have different ways to do this.
Moreover, please keep in mind that some applications (e.g. Firefox) use their own trusted certificates store. For that applications, you should import the certificate in the appropriate way.
Create the file "redirect.py", with the following content:
import SimpleHTTPServer import SocketServer import ssl class FakeRedirect(SimpleHTTPServer.SimpleHTTPRequestHandler): def do_GET(self): print self.path self.send_response(301) new_path = '%s%s'%('https://cdn.rawgit.com', self.path) self.send_header('Location', new_path) self.end_headers() htsrv = SocketServer.TCPServer(("", 443), FakeRedirect) htsrv.socket = ssl.wrap_socket (htsrv.socket, certfile='./ghrcert.crt', keyfile='./ghrkey.pem', server_side=True) htsrv.serve_forever()
Run the script (it needs root privileges to bind to https port - 443/tcp):
sudo python redirect.py
- Thumbs-up for the author! (Marco Bellaccini - marco.bellaccini(at!)gmail.com)
This gist is released under the Creative Commons Attribution 4.0 International license.
work well for me. ty!