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-18.12.28.tar.gz
(4.8 kB
view details)
Built Distribution
File details
Details for the file cgiproxy-18.12.28.tar.gz
.
File metadata
- Download URL: cgiproxy-18.12.28.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13342558a08cf893c453ccecc0589f2bad77740bf5981e3bc7fc4a0aa1ba3035 |
|
MD5 | c836b25b614207e9d76fa5823c98e7d5 |
|
BLAKE2b-256 | 1f941e88b8b6ca4ad34a664288bd68cd8f64af920b8ccded54c97b244bf329d1 |
File details
Details for the file cgiproxy-18.12.28-py3-none-any.whl
.
File metadata
- Download URL: cgiproxy-18.12.28-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db7affdf87c86a8f6a9c30e70aaa169b86b7fdcd8c10c2439adc5350af4f790f |
|
MD5 | 645820da12f7695bc9c8d4602dd91412 |
|
BLAKE2b-256 | a8224ea2880e470076f6373c47d997c5dc64a59b11ad1d42608e16ad9b91197b |