Skip to content

Commit

Permalink
override _set_proxy_headers
Browse files Browse the repository at this point in the history
This forces _set_proxy_headers in urllib3.poolmanager.ProxyManager to
not send "Accept: */*" through the proxy. A proxy like mitmproxy will
pass along this "Accept" header to the destination, which is not always
the desired result.
  • Loading branch information
kanzure committed Jan 10, 2013
1 parent fa1f9f4 commit 3f89673
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions careful_requests/careful_requests.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -98,6 +98,15 @@ def connect(self):
requests.packages.urllib3.connectionpool.HTTPSConnection = CarefulHTTPSConnection requests.packages.urllib3.connectionpool.HTTPSConnection = CarefulHTTPSConnection
requests.packages.urllib3.connectionpool.VerifiedHTTPSConnection = CarefulVerifiedHTTPSConnection requests.packages.urllib3.connectionpool.VerifiedHTTPSConnection = CarefulVerifiedHTTPSConnection


def _set_proxy_headers(self, headers=None):
headers = headers or {}

# headers['Accept'] = '*/*'
# headers['Proxy-Connection'] = 'Keep-Alive'

return headers
requests.packages.urllib3.poolmanager.ProxyManager._set_proxy_headers = _set_proxy_headers

class CarefulSession(requests.sessions.Session): class CarefulSession(requests.sessions.Session):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
config = {} config = {}
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


setup( setup(
name="careful-requests", name="careful-requests",
version="0.1.3", version="0.1.4",
url="https://github.com/kanzure/careful-requests", url="https://github.com/kanzure/careful-requests",
license="BSD", license="BSD",
author="Bryan Bishop", author="Bryan Bishop",
Expand Down

0 comments on commit 3f89673

Please sign in to comment.