Skip to content

Commit 62b4677

Browse files
committed
more doc updates
1 parent a071ae1 commit 62b4677

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

README.md

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
1-
The `python-proxy-headers` package provides support for handling custom proxy headers when making HTTP requests in various python modules.
1+
# Python Proxy Headers
2+
3+
The `python-proxy-headers` package provides support for handling custom proxy headers when making HTTPS requests in various python modules.
24

35
We currently provide extensions to the following packages:
46

57
* [urllib3](https://urllib3.readthedocs.io/en/stable/)
68
* [requests](https://docs.python-requests.org/en/latest/index.html)
7-
* [httpx](https://www.python-httpx.org/)
89
* [aiohttp](https://docs.aiohttp.org/en/stable/index.html)
10+
* [httpx](https://www.python-httpx.org/)
911

1012
None of these modules provide good support for parsing custom response headers from proxy servers. And some of them make it hard to send custom headers to proxy servers. So we at [ProxyMesh](https://proxymesh.com) made these extension modules to support our customers that use Python and want to use custom headers to control our proxy behavior. But these modules can work for handling custom headers with any proxy.
1113

12-
Examples for how to use these extension modules are described below.
14+
*If you are looking for [Scrapy](https://scrapy.org/) support, please see our [scrapy-proxy-headers](https://github.com/proxymesh/scrapy-proxy-headers) project.*
15+
16+
## Installation
17+
18+
Examples for how to use these extension modules are described below. You must first do the following:
19+
20+
1. `pip install python-proxy-headers`
21+
2. Install the appropriate package based on the python module you want to use.
22+
23+
This package does not have any dependencies because we don't know which module you want to use.
1324

1425
## urllib3
1526

16-
If you just want to send custom proxy headers, but don't need to receive proxy response headers, then you can use urllib3 directly, like so:
27+
If you just want to send custom proxy headers, but don't need to receive proxy response headers, then you can [urllib3.ProxyManager](https://urllib3.readthedocs.io/en/stable/reference/urllib3.poolmanager.html#urllib3.ProxyManager), like so:
1728

1829
``` python
1930
import urllib3
2031
proxy = urllib3.ProxyManager('http://PROXYHOST:PORT', proxy_headers={'X-ProxyMesh-Country': 'US'})
2132
r = proxy.request('GET', 'https://api.ipify.org?format=json')
2233
```
2334

24-
Note that when using this method, if you keep reusing the same `ProxyManager` instance, you may be re-using the proxy connection, which may have different behavior than if you create a new proxy connection for each request. For example, with ProxyMesh, you may keep getting the same IP address if you reuse the proxy connection.
35+
Note that when using this method, if you keep reusing the same `ProxyManager` instance, you may be re-using the proxy connection, which may have different behavior than if you create a new proxy connection for each request. For example, with ProxyMesh you may keep getting the same IP address if you reuse the proxy connection.
2536

2637
To get proxy response headers, use our extension module like this:
2738

@@ -32,11 +43,11 @@ r = proxy.request('GET', 'https://api.ipify.org?format=json')
3243
r.headers['X-ProxyMesh-IP']
3344
```
3445

35-
You can also pass `proxy_headers` into the `ProxyHeaderManager` as well. For example, you pass back the same `X-ProxyMesh-IP` to ensure you get the same IP address on subsequent requests.
46+
You can also pass `proxy_headers` into our `ProxyHeaderManager` as well. For example, you can pass back the same `X-ProxyMesh-IP` header to ensure you get the same IP address on subsequent requests.
3647

3748
## requests
3849

39-
The requests adapter builds on the `urllib3_proxy_manager` module to make it easy to pass in proxy headers and receive proxy response headers.
50+
The requests adapter builds on our `urllib3_proxy_manager` module to make it easy to pass in proxy headers and receive proxy response headers.
4051

4152
``` python
4253
from python_proxy_headers import requests_adapter
@@ -57,7 +68,7 @@ async with aiohttp.ClientSession() as session:
5768
await r.text()
5869
```
5970

60-
However, if you want to get proxy response, you should use our extenion module:
71+
However, if you want to get proxy response, you should use our extension module:
6172

6273
``` python
6374
from python_proxy_headers import aiohttp_proxy
@@ -75,8 +86,8 @@ httpx also supports proxy headers by default, though it's not documented:
7586
``` python
7687
import httpx
7788
proxy = httpx.Proxy('http://PROXYHOST:PORT', headers={'X-ProxyMesh-Country': 'US'})
78-
mounts = {'http://': httpx.HTTPTransport(proxy=proxy), 'https://': httpx.HTTPTransport(proxy=proxy)}
79-
with httpx.Client(mounts=mounts) as client:
89+
transport = HTTPProxyTransport(proxy=proxy)
90+
with httpx.Client(mounts={'http://': transort, 'https://': transport}) as client:
8091
r = client.get('https://api.ipify.org?format=json')
8192
```
8293

@@ -117,4 +128,4 @@ r.headers['X-ProxyMesh-IP']
117128
```
118129

119130
Our httpx helper module internally provides extension classes for [httpcore](https://www.encode.io/httpcore/), for handling proxy headers over tunnel connections.
120-
You can use those classes too if you're building on top of httpcore.
131+
You can use those classes if you're building on top of httpcore.

0 commit comments

Comments
 (0)