The simple HTTP proxy.
Project description
CGI Proxy
Simple CGI HTTP Proxy.
- Sets the
X-Forwarded-For
header with the client IP address; - Sets the
User-Agent
header with the client'User-Agent
string; - Decodes
gzip
-ed content; - Prints all errors to
stderr
; - Uses
urllib2
for Python 2 andurllib.request
for Python 3.
Installation
Install from PyPI using pip
:
$ pip install cgiproxy
Methods
do_get(url, headers=None)
Performs GET
request.
Arguments:
url
- The request URL asstr
.headers
- Optional HTTP request headers asdict
.
Returns:
- A tuple of
(content, status_code, response_headers)
do_head(url, headers=None)
Performs HEAD
request.
Arguments:
url
- The request URL asstr
.headers
- Optional HTTP request headers asdict
.
Returns:
- A tuple of
(content='', status_code, response_headers)
do_post(url, data=None, headers=None)
Performs POST
request. Converts query to POST
params if data
is None
.
Arguments:
url
- The request URL asstr
.data
- Optional HTTP POST data as URL-encodedstr
.headers
- Optional HTTP request headers asdict
.
Returns:
- A tuple of
(content, status_code, response_headers)
get_http_status(url, headers=None)
Gets HTTP status code.
Arguments:
url
- The request URL asstr
.headers
- Optional HTTP request headers asdict
.
Returns:
- An HTTP status code.
get_response_headers(url, headers=None)
Gets HTTP response headers.
Arguments:
url
- The request URL asstr
.headers
- Optional HTTP request headers asdict
.
Returns:
- An HTTP response headers as
dict
.
Examples
import cgiproxy
status = cgiproxy.get_http_status('https://www.pageportrait.com/')
print(200 == status)
headers = cgiproxy.get_response_headers('https://komito.net/')
print(headers.get('content-type'))
content, status, headers = cgiproxy.do_head('https://www.dtm.io/')
print('' == content)
print(200 == status)
print(headers.get('content-type'))
content, status, headers = cgiproxy.do_get('https://www.dtm.io/', headers={
'User-Agent': 'Mozilla/5.0 (compatible; Darwin/18.2.0) cgiproxy/18.12',
'X-Custom-Header': 'value'
})
print('' != content)
print(200 == status)
print(headers.get('content-type'))
content, status, headers = cgiproxy.do_post('https://example.com/', data='aaa%3Dbbb%26ccc%3Dddd')
print('' != content)
print(200 == status)
print(headers.get('content-type'))
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
cgiproxy-20.11.14.tar.gz
(5.1 kB
view hashes)
Built Distributions
Close
Hashes for cgiproxy-20.11.14-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c70e5e921d2a7367c0743aed1d5b45e12df6f8a1b23b111983230fecb993798 |
|
MD5 | 8949888719d5f69fbe0cf693a8582302 |
|
BLAKE2b-256 | 9f9c67e0ded3c6b7f6e46a0a14411a1b886e34588e2b044fc5fb62e59e2519b1 |
Close
Hashes for cgiproxy-20.11.14-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 822b8363db7918ffb9b4c53e314d023b5a095377f0c0097067695a27c7ec7392 |
|
MD5 | 87fdc7de3d28ef7201a4c4e97c3d28cb |
|
BLAKE2b-256 | df91a7124563fa8f37436f6ab7c364376193a477b98b2c52fe2830d7b37b3cef |