diff options
author | James Taylor <user234683@users.noreply.github.com> | 2019-02-25 20:47:49 -0800 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2019-02-25 20:47:49 -0800 |
commit | 1e1f55c9e5d98ba076bc67e7abe9e4d77d84c65b (patch) | |
tree | 56eeabd9f7f0813c4b02f03f865d7cae35277d29 /server.py | |
parent | b32330be4f15dd044e6212f526e52375f0a0f6c2 (diff) | |
download | yt-local-1e1f55c9e5d98ba076bc67e7abe9e4d77d84c65b.tar.lz yt-local-1e1f55c9e5d98ba076bc67e7abe9e4d77d84c65b.tar.xz yt-local-1e1f55c9e5d98ba076bc67e7abe9e4d77d84c65b.zip |
Use persistent connections
Diffstat (limited to 'server.py')
-rw-r--r-- | server.py | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -2,16 +2,19 @@ from gevent import monkey monkey.patch_all() import gevent.socket -from gevent.pywsgi import WSGIServer from youtube.youtube import youtube +from youtube import util import http_errors +import settings + +from gevent.pywsgi import WSGIServer import urllib +import urllib3 import socket import socks, sockshandler import subprocess import re -import settings @@ -31,15 +34,14 @@ def proxy_site(env, start_response): url += '?' + env['QUERY_STRING'] - req = urllib.request.Request(url, headers=headers) - if settings.route_tor: - opener = urllib.request.build_opener(sockshandler.SocksiPyHandler(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9150)) - response = opener.open(req, timeout=10) - else: - response = urllib.request.urlopen(req, timeout=10) + content, response = util.fetch_url(url, headers, return_response=True) + + headers = response.getheaders() + if isinstance(headers, urllib3._collections.HTTPHeaderDict): + headers = headers.items() - start_response('200 OK', response.getheaders() ) - return response.read() + start_response('200 OK', headers ) + return content site_handlers = { 'youtube.com':youtube, |