kevinsl / wsgi-intercept

Automatically exported from code.google.com/p/wsgi-intercept
Other
0 stars 0 forks source link

Add "requests" support #23

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Requests uses a bundled urllib3, here's what I had to do to make wsgi_intercept 
work with it:

I propose that we add this in a requests_intercept module (with cleaned up 
imports ;) )

def install_opener():
    # httplib patch
    from wsgi_intercept.httplib_intercept import install
    install()

    # requests' patch
    import wsgi_intercept
    from requests.packages.urllib3 import connectionpool

    connectionpool.old_http = connectionpool.HTTPConnection
    connectionpool.HTTPConnection = wsgi_intercept.WSGI_HTTPConnection

    connectionpool.old_https = connectionpool.HTTPSConnection
    connectionpool.HTTPSConnection = wsgi_intercept.WSGI_HTTPSConnection

    # we need settimeout()
    wsgi_intercept.wsgi_fake_socket.settimeout = lambda self, timeout: None

def uninstall_opener():
    # httplib unpatch
    from wsgi_intercept.httplib_intercept import uninstall
    uninstall()

    # requests' unpatch
    import wsgi_intercept
    from requests.packages.urllib3 import connectionpool

    connectionpool.HTTPConnection = connectionpool.old_http
    connectionpool.HTTPSConnection = connectionpool.old_https

Original issue reported on code.google.com by ziade.ta...@gmail.com on 15 Dec 2011 at 12:24

GoogleCodeExporter commented 8 years ago
Hi Tarek, supporting urllib3 sounds like a good idea. If I get time I'll apply 
it with a test or two. If you want to have a go at it, you can run the tests 
with tox from the source.

Original comment by kumar.mcmillan on 16 Dec 2011 at 7:44

GoogleCodeExporter commented 8 years ago
@So has no one had time to add support for this in the last few years? 

Original comment by son...@gmail.com on 1 May 2013 at 9:06

GoogleCodeExporter commented 8 years ago
is wsgi-intercept abandoned?

Original comment by irae_ver...@bitcoinsberlin.com on 6 Nov 2013 at 3:40