FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
proxy-examples/python/httpx-proxy.py at main · proxymesh/proxy-examples · GitHub
proxymesh
/
proxy-examples
Public
Notifications
You must be signed in to change notification settings
Fork
1
Star
4
Code
Issues
4
Pull requests
1
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
proxy-examples
/
python
/
httpx-proxy.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
31 lines (24 loc) · 1006 Bytes
Breadcrumbs
proxy-examples
/
python
/
httpx-proxy.py
Copy path
File metadata and controls
31 lines (24 loc) · 1006 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
"""
httpx (sync) with an HTTP proxy.
Configuration via environment variables:
PROXY_URL - Proxy URL (required), e.g., http://user:pass@proxy:8080
TEST_URL - URL to request (default: https://api.ipify.org?format=json)
RESPONSE_HEADER - Optional header name to print from the response
Documentation: https://www.python-httpx.org/advanced/proxies/
"""
import
os
import
sys
import
httpx
proxy_url
=
os
.
environ
.
get
(
'PROXY_URL'
)
or
os
.
environ
.
get
(
'HTTPS_PROXY'
)
if
not
proxy_url
:
print
(
'Error: Set PROXY_URL environment variable'
,
file
=
sys
.
stderr
)
sys
.
exit
(
1
)
test_url
=
os
.
environ
.
get
(
'TEST_URL'
,
'https://api.ipify.org?format=json'
)
response_header
=
os
.
environ
.
get
(
'RESPONSE_HEADER'
)
with
httpx
.
Client
(
proxy
=
proxy_url
,
timeout
=
30.0
)
as
client
:
response
=
client
.
get
(
test_url
)
print
(
f'Status:
{
response
.
status_code
}
'
)
print
(
f'Body:
{
response
.
text
}
'
)
if
response_header
:
print
(
f'
{
response_header
}
:
{
response
.
headers
.
get
(
response_header
)
}
'
)
Back
|
FazBrowse Home
|
New Git URL