Experiments
Before You Start
Run the proxy in one terminal so you can read the logs:
segproxy --listen-host 127.0.0.1 --listen-port 8080 --log-level DEBUG
1) HTTP request through the proxy
What to run:
curl -v -x http://127.0.0.1:8080 http://example.com/
DEBUG HTTP forward example.com:80 / (rule=<default> score=-1 action=direct mode=direct strategy=none)
2) HTTPS website through CONNECT
What to run:
curl -v -x http://127.0.0.1:8080 https://example.com/
DEBUG CONNECT tunnel example.com:443 (rule=<default> score=-1 action=direct mode=direct strategy=none chunk=1024 delay_ms=0)
3) Block a domain rule
What to run (start the proxy with a rule):
segproxy --listen-host 127.0.0.1 --listen-port 8080 --log-level DEBUG --segment-rule "example.com=direct,action=block,reason=demo"
curl -v -x http://127.0.0.1:8080 http://example.com/
DEBUG HTTP forward example.com:80 / (rule=example.com score=1 action=block mode=direct strategy=none)
4) Route traffic via an upstream proxy
This needs another proxy running at 127.0.0.1:3128. If you do not have one, this test will return 502. If you do not have an upstream proxy, skip this experiment.
What to run (start the proxy with a rule):
segproxy --listen-host 127.0.0.1 --listen-port 8080 --log-level DEBUG --segment-rule "*.example.com=segment_upstream,action=upstream,upstream=127.0.0.1:3128"
curl -v -x http://127.0.0.1:8080 http://example.com/
DEBUG HTTP forward example.com:80 / (rule=*.example.com score=1 action=upstream mode=segment_upstream strategy=none)
5) Segment HTTPS CONNECT only
What to run (start the proxy with a rule):
segproxy --listen-host 127.0.0.1 --listen-port 8080 --log-level DEBUG --segment-rule "*.example.com=segment_upstream,action=direct,scheme=https,method=CONNECT,strategy=random,min=256,max=1024,delay=5"
curl -v -x http://127.0.0.1:8080 https://example.com/
DEBUG CONNECT tunnel example.com:443 (rule=*.example.com score=3 action=direct mode=segment_upstream strategy=random chunk=1024 delay_ms=5)
Experiments using --access-log (v0.5.0+)
Experiment 1: Direct vs Upstream routing
Goal: - Compare direct routing vs upstream routing using ACCESS lines.
Setup:
- If you want to test upstream, run an upstream proxy on 127.0.0.1:3128.
Steps: 1) Start the proxy:
segproxy --listen-host 127.0.0.1 --listen-port 8080 --access-log \
--segment-rule "example.com=direct" \
--segment-rule "example.org=segment_upstream,action=upstream,upstream=127.0.0.1:3128"
curl -x http://127.0.0.1:8080 http://example.com/
curl -x http://127.0.0.1:8080 http://example.org/
What to look for (expected ACCESS fields):
- rid should be different for each request.
- action should be direct for example.com and upstream for example.org.
- mode and strategy show the policy used.
- If you need the upstream host/port, run with --log-level debug and match the same rid.
Notes / Troubleshooting:
- If you do not have an upstream proxy, the upstream request will return 502.
- The ACCESS line is still useful for seeing the action and rid.
Experiment 2: Segmentation fixed vs none (HTTP body)
Goal:
- See how strategy=fixed and strategy=none appear in ACCESS lines.
Setup:
- This experiment needs an upstream proxy at 127.0.0.1:3128.
If you do not have an upstream proxy, skip this experiment.
Steps: 1) Start the proxy with a fixed strategy:
segproxy --listen-host 127.0.0.1 --listen-port 8080 --access-log \
--segment-rule "example.com=segment_upstream,action=upstream,upstream=127.0.0.1:3128,scheme=http,method=POST,path_prefix=/upload,strategy=fixed,chunk=256"
curl -x http://127.0.0.1:8080 -X POST --data-binary "hello" http://example.com/upload
strategy=none and repeat:
segproxy --listen-host 127.0.0.1 --listen-port 8080 --access-log \
--segment-rule "example.com=segment_upstream,action=upstream,upstream=127.0.0.1:3128,scheme=http,method=POST,path_prefix=/upload,strategy=none"
What to look for (expected ACCESS fields):
- strategy=fixed vs strategy=none.
- rid changes each request.
- The HTTP result may look the same, because segmentation only changes how the body is sent.
Notes / Troubleshooting:
- If you do not have an upstream proxy, you will see 502.
- If you want more detail, add --log-level debug and match logs by rid.
Experiment 3: DNS cache + UDP→TCP fallback
Goal: - Observe DNS cache hits and DNS transport in ACCESS lines.
Setup:
- Use a reachable DNS server (example: 1.1.1.1).
Steps: 1) Start the proxy with DNS cache:
segproxy --listen-host 127.0.0.1 --listen-port 8080 --access-log \
--dns-server 1.1.1.1 --dns-transport udp --dns-cache-size 100
curl -x http://127.0.0.1:8080 http://example.com/
curl -x http://127.0.0.1:8080 http://example.com/
What to look for (expected ACCESS fields):
- dns=system or dns=custom.
- cache=miss on the first request and cache=hit on the second.
- transport=udp or transport=tcp.
- fallback=1 only when UDP fails and TCP is used.
Notes / Troubleshooting:
- If you never see fallback=1, your UDP queries are working.
- If DNS fails, you may see a 502 error from the proxy.
- Fallback can be hard to reproduce. It is OK to focus on cache miss/hit.
Reminder:
These experiments are for learning.
Logs can be verbose; use --log-level debug if needed.