-
-
Save RichardHum/639b04d918e4e7e8bb7e1d15ed344b01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python | |
# yo dawg I heard you needed a proxy for your proxy | |
# this is a very slow proof of concept | |
import socketserver | |
import http.server | |
import urllib.request | |
#whatever localhost port we want to listen on | |
g_port = 9999 | |
#where to redirect requests to | |
g_redirect_url = "http://example.com/proxy/proxy.ashx" | |
#redirect referer | |
g_referer_url = "http://example.com/whatever/" | |
class MyProxy(http.server.SimpleHTTPRequestHandler): | |
def do_GET(self): | |
# self.path will be the junk after our server/port used in the URL, including the leading slash | |
# get rid of leading slash | |
url=self.path[1:] | |
# add the arcgis proxy | |
url = g_redirect_url + "?" + url | |
self.headers["Referer"] = g_referer_url | |
self.path = url | |
print("") | |
print("URL:", url) | |
print(self.headers) | |
self.send_response(200) | |
self.end_headers() | |
req = urllib.request.Request(url, headers=self.headers) | |
print(" Getting...") | |
self.copyfile(urllib.request.urlopen(req), self.wfile) | |
print(" done!") | |
do_HEAD = do_GET | |
do_POST = do_GET | |
do_PUT = do_GET | |
do_DELETE = do_GET | |
do_OPTIONS = do_GET | |
# localhost on g_port defined above | |
httpd = socketserver.ThreadingTCPServer(('', g_port), MyProxy) | |
print("Serving on http://localhost:{}".format(g_port)) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment