forked from DeepGraphLearning/ULTRA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleULTRAProxy.py
32 lines (23 loc) · 953 Bytes
/
simpleULTRAProxy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# A proxy just for the SPOKE API
from socketserver import ForkingTCPServer
import http.server
import urllib.request
PORT = 9097
URL_REQUIREMENT=['https://www.dropbox.com','https://zenodo.org','https://raw.githubusercontent.com','reltrans.s3.us-east-2.amazonaws.com']
class MyProxy(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
url=self.path[1:] # remove trailing /
good_url=False
for s in URL_REQUIREMENT:
if url.find(s) != -1:
good_url=True
if not good_url:
self.send_response(403)
print(f"Rejecting URL because it does not have the the required string")
else:
self.send_response(200)
self.end_headers()
self.copyfile(urllib.request.urlopen(url), self.wfile)
httpd = ForkingTCPServer(('', PORT), MyProxy)
print (f"Now serving at {PORT}")
httpd.serve_forever()