-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conditional host resolving #422
Labels
duplicate
Issue already exists
Comments
I do this with requests using this evil adapter I made: from requests.adapters import HTTPAdapter
from types import MethodType
# http://docs.python-requests.org/en/master/_modules/requests/adapters/
class TransparentProxyAdapter(HTTPAdapter):
# opens sockets to an arbitrary fixhost instead of deriving it from the URL's Host
def __init__(self, tproxy, **kwargs):
self.tproxy = tproxy
self.timeout = 5
super(TransparentProxyAdapter,self).__init__(**kwargs)
def get_connection(self, url, proxies=None):
# monkeypatch the connection pool's _new_conn()
conn = super(TransparentProxyAdapter,self).get_connection(url, proxies)
conn.fixhost = self.tproxy
conn._new_conn = MethodType(self.monkeypatched_new_conn.__func__, conn, conn.__class__)
return conn
# https://github.com/shazow/urllib3/blob/1.16/urllib3/connectionpool.py#L208
def monkeypatched_new_conn(self):
# https://hg.python.org/cpython/file/2.7/Lib/httplib.py
def monkeypatched_connect(self):
orighost = self.host
self.host = self.fixhost #switcheroo
self.orig_connect()
self.host = orighost #put it back
self.num_connections += 1
# monkeypatch the connection's connect()
if self.fixhost != None and self.proxy == None:
conn = self.ConnectionCls(self.host, self.port, timeout=self.timeout)
conn.fixhost = self.fixhost
conn.orig_connect = conn.connect
conn.connect = MethodType(monkeypatched_connect, conn, conn.__class__)
return conn unfortunately urllib3 has no hooking to perform resolution statically and ignoring socket.getaddrinfo, which would be more comparable to how --resolve works with libcurl. |
Duplicate of #99 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey ,
First of all really great tool. Cannot imagine work without now :) What I would be looking for is what we have in cURL which allows resolve host name on the fly when making request
Is it already available and I'm missing something or could that be a feature request ?
The text was updated successfully, but these errors were encountered: