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.
Install from PyPI using pip
:
$ pip install cgiproxy
Performs GET
request.
Arguments:
url
- The request URL asstr
.headers
- Optional HTTP request headers asdict
.
Returns:
- A tuple of
(content, status_code, response_headers)
Performs HEAD
request.
Arguments:
url
- The request URL asstr
.headers
- Optional HTTP request headers asdict
.
Returns:
- A tuple of
(content='', status_code, response_headers)
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)
Gets HTTP status code.
Arguments:
url
- The request URL asstr
.headers
- Optional HTTP request headers asdict
.
Returns:
- An HTTP status code.
Gets HTTP response headers.
Arguments:
url
- The request URL asstr
.headers
- Optional HTTP request headers asdict
.
Returns:
- An HTTP response headers as
dict
.
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'))