Skip to content

Commit fa89944

Browse files
committed
Add initial Sphinx docs
1 parent 9314d05 commit fa89944

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1361
-159
lines changed

.flake8

+15-5
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,19 @@ pytest-parametrize-values-row-type = tuple
230230
pytest-mark-no-parentheses = true
231231

232232
# flake8-rst-docstrings
233+
rst-directives =
234+
spelling
233235
rst-roles =
234-
# Built-in Sphinx roles:
235-
py:class,
236-
py:meth,
237-
# Sphinx's internal role:
238-
event,
236+
# Built-in Sphinx roles:
237+
class,
238+
data,
239+
exc,
240+
meth,
241+
term,
242+
py:class,
243+
py:data,
244+
py:exc,
245+
py:meth,
246+
py:term,
247+
# Sphinx's internal role:
248+
event,

.github/workflows/test-library.yml

+6
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ jobs:
305305
--parallel auto
306306
--parallel-live
307307
--skip-missing-interpreters false
308+
--skip-pkg-install
308309
- name: Verify that the artifacts with expected names got created
309310
run: >-
310311
ls -1
@@ -335,6 +336,10 @@ jobs:
335336
toxenv:
336337
- lint
337338
- metadata-validation
339+
- build-docs
340+
- doctest-docs
341+
- linkcheck-docs
342+
- spellcheck-docs
338343
fail-fast: false
339344

340345
env:
@@ -417,6 +422,7 @@ jobs:
417422
--parallel auto
418423
--parallel-live
419424
--skip-missing-interpreters false
425+
--skip-pkg-install
420426
421427
test:
422428
name: 🐍${{ matrix.python }} @ ${{ matrix.os }}

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ repos:
7474
$
7575
- id: requirements-txt-fixer
7676
exclude: >-
77-
^requirements(|-(release|testing|tunnel))\.txt$
77+
^(docs/requirements|requirements(|-(release|testing|tunnel)))\.txt$
7878
# Non-modifying checks:
7979
- id: name-tests-test
8080
args:

.readthedocs.yml

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Read the Docs configuration file
2+
# See https://docs.readthedocs.io/en/stable/config-file/v2.html
3+
# for details
4+
5+
---
6+
7+
# Required
8+
version: 2
9+
10+
# Build documentation in the docs/ directory with Sphinx
11+
sphinx:
12+
builder: dirhtml
13+
configuration: docs/conf.py
14+
fail_on_warning: true
15+
16+
# Optionally build your docs in additional formats
17+
# such as PDF and ePub
18+
formats: []
19+
20+
submodules:
21+
include: all # []
22+
exclude: []
23+
recursive: true
24+
25+
build:
26+
os: ubuntu-20.04
27+
tools:
28+
python: >- # PyYAML parses it as float `3.1` it it's not an explicit string
29+
3.10
30+
31+
# Optionally set the version of Python and requirements required
32+
# to build docs
33+
python:
34+
install:
35+
- method: pip
36+
path: .
37+
- requirements: requirements-tunnel.txt
38+
- requirements: docs/requirements.txt
39+
system_packages: false
40+
41+
...

README.md

+49-42
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
⚡ Fast • 🪶 Lightweight • 0️⃣ Dependency • 🔌 Pluggable • 😈 TLS interception • 🔒 DNS-over-HTTPS • 🔥 Poor Man's VPN • ⏪ Reverse & ⏩ Forward • 👮🏿 "Proxy Server" framework • 🌐 "Web Server" framework • ➵ ➶ ➷ ➠ "PubSub" framework • 👷 "Work" acceptor & executor framework
55
</p>
66

7+
[//]: # (DO-NOT-REMOVE-docs-badges-START)
8+
79
[![PyPi Monthly](https://img.shields.io/pypi/dm/proxy.py?style=for-the-badge&color=darkgreen)](https://pypi.org/project/proxy.py/)
810
[![Docker Pulls](https://img.shields.io/docker/pulls/abhinavsingh/proxy.py?style=for-the-badge&color=darkgreen)](https://hub.docker.com/r/abhinavsingh/proxy.py)
911
[![No Dependencies](https://img.shields.io/static/v1?label=dependencies&message=0&style=for-the-badge&color=darkgreen)](https://github.com/abhinavsingh/proxy.py)
@@ -82,9 +84,9 @@
8284
- [Ephemeral Port](#ephemeral-port)
8385
- [Loading Plugins](#loading-plugins)
8486
- [Unit testing with proxy.py](#unit-testing-with-proxypy)
85-
- [proxy.TestCase](#proxytestcase)
87+
- [`proxy.TestCase`](#proxytestcase)
8688
- [Override Startup Flags](#override-startup-flags)
87-
- [With unittest.TestCase](#with-unittesttestcase)
89+
- [With `unittest.TestCase`](#with-unittesttestcase)
8890
- [Utilities](#utilities)
8991
- [TCP](#tcp-sockets)
9092
- [new_socket_connection](#new_socket_connection)
@@ -105,7 +107,7 @@
105107
- [Unable to connect with proxy.py from remote host](#unable-to-connect-with-proxypy-from-remote-host)
106108
- [Basic auth not working with a browser](#basic-auth-not-working-with-a-browser)
107109
- [Docker image not working on MacOS](#docker-image-not-working-on-macos)
108-
- [ValueError: filedescriptor out of range in select](#valueerror-filedescriptor-out-of-range-in-select)
110+
- [`ValueError: filedescriptor out of range in select`](#valueerror-filedescriptor-out-of-range-in-select)
109111
- [None:None in access logs](#nonenone-in-access-logs)
110112
- [OSError when wrapping client for TLS Interception](#oserror-when-wrapping-client-for-tls-interception)
111113
- [Plugin Developer and Contributor Guide](#plugin-developer-and-contributor-guide)
@@ -122,6 +124,8 @@
122124
- [v1.x](#v1x)
123125
- [v0.x](#v0x)
124126

127+
[//]: # (DO-NOT-REMOVE-docs-badges-END)
128+
125129
# Features
126130
- Fast & Scalable
127131

@@ -170,7 +174,7 @@
170174
- Optionally, enable builtin [Web Server Plugins](#http-web-server-plugins). Example:
171175
- `--plugins proxy.plugin.ReverseProxyPlugin`
172176
- Plugin API is currently in development phase, expect breaking changes
173-
- Realtime Dashboard
177+
- Real-time Dashboard
174178
- Optionally, enable [proxy.py dashboard](#run-dashboard).
175179
- Available at `http://localhost:8899/dashboard`.
176180
- [Inspect, Monitor, Control and Configure](#inspect-traffic) `proxy.py` at runtime
@@ -423,7 +427,7 @@ You can override flag from command line when starting the docker container. For
423427

424428
Add support for short links in your favorite browsers / applications.
425429

426-
[![Shortlink Plugin](https://raw.githubusercontent.com/abhinavsingh/proxy.py/develop/shortlink.gif)](https://github.com/abhinavsingh/proxy.py#shortlinkplugin)
430+
[![Shortlink Plugin](https://raw.githubusercontent.com/abhinavsingh/proxy.py/develop/shortlink.gif)](https://github.com/abhinavsingh/proxy.py#user-content-shortlinkplugin)
427431

428432
Start `proxy.py` as:
429433

@@ -438,17 +442,17 @@ across all browsers.
438442

439443
Following short links are enabled by default:
440444

441-
| Short Link | Destination URL |
442-
| :--------: | :--------------: |
443-
| a/ | amazon.com |
444-
| i/ | instagram.com |
445-
| l/ | linkedin.com |
446-
| f/ | facebook.com |
447-
| g/ | google.com |
448-
| t/ | twitter.com |
449-
| w/ | web.whatsapp.com |
450-
| y/ | youtube.com |
451-
| proxy/ | localhost:8899 |
445+
| Short Link | Destination URL |
446+
| :--------: | :--------------: |
447+
| a/ | `amazon.com` |
448+
| i/ | `instagram.com` |
449+
| l/ | `linkedin.com` |
450+
| f/ | `facebook.com` |
451+
| g/ | `google.com` |
452+
| t/ | `twitter.com` |
453+
| w/ | `web.whatsapp.com` |
454+
| y/ | `youtube.com` |
455+
| proxy/ | `localhost:8899` |
452456

453457
### ModifyPostDataPlugin
454458

@@ -461,7 +465,7 @@ Start `proxy.py` as:
461465
--plugins proxy.plugin.ModifyPostDataPlugin
462466
```
463467

464-
By default plugin replaces POST body content with hardcoded `b'{"key": "modified"}'`
468+
By default plugin replaces POST body content with hard-coded `b'{"key": "modified"}'`
465469
and enforced `Content-Type: application/json`.
466470

467471
Verify the same using `curl -x localhost:8899 -d '{"key": "value"}' http://httpbin.org/post`
@@ -763,7 +767,7 @@ Modify plugin to your taste e.g. Allow specific IP addresses only.
763767

764768
### ModifyChunkResponsePlugin
765769

766-
This plugin demonstrate how to modify chunked encoded responses. In able to do so, this plugin uses `proxy.py` core to parse the chunked encoded response. Then we reconstruct the response using custom hardcoded chunks, ignoring original chunks received from upstream server.
770+
This plugin demonstrate how to modify chunked encoded responses. In able to do so, this plugin uses `proxy.py` core to parse the chunked encoded response. Then we reconstruct the response using custom hard-coded chunks, ignoring original chunks received from upstream server.
767771

768772
Start `proxy.py` as:
769773

@@ -784,14 +788,14 @@ plugin
784788
* Closing connection 0
785789
```
786790

787-
Modify `ModifyChunkResponsePlugin` to your taste. Example, instead of sending hardcoded chunks, parse and modify the original `JSON` chunks received from the upstream server.
791+
Modify `ModifyChunkResponsePlugin` to your taste. Example, instead of sending hard-coded chunks, parse and modify the original `JSON` chunks received from the upstream server.
788792

789793
### CloudflareDnsResolverPlugin
790794

791795
This plugin uses `Cloudflare` hosted `DNS-over-HTTPS` [API](https://developers.cloudflare.com/1.1.1.1/encrypted-dns/dns-over-https/make-api-requests/dns-json) (json).
792796

793797
`DoH` mandates a HTTP2 compliant client. Unfortunately `proxy.py`
794-
doesn't provide that yet, so we use a dependency. Install it:
798+
does not provide that yet, so we use a dependency. Install it:
795799

796800
```console
797801
pip install "httpx[http2]"
@@ -811,7 +815,7 @@ Use `--cloudflare-dns-mode family` to also enable adult content protection too.
811815

812816
This plugin demonstrate how to use a custom DNS resolution implementation with `proxy.py`.
813817
This example plugin currently uses Python's in-built resolution mechanism. Customize code
814-
to your taste. Example, query your custom DNS server, implement DoH or other mechanisms.
818+
to your taste. Example, query your custom DNS server, implement `DoH` or other mechanisms.
815819

816820
Start `proxy.py` as:
817821

@@ -969,7 +973,7 @@ response from the server. Start `proxy.py` as:
969973
--ca-signing-key-file ca-signing-key.pem
970974
```
971975

972-
[![NOTE](https://img.shields.io/static/v1?label=MacOS&message=note&color=yellow)](https://github.com/abhinavsingh/proxy.py#flags) Also provide explicit CA bundle path needed for validation of peer certificates. See `--ca-file` flag.
976+
[![NOTE](https://img.shields.io/static/v1?label=MacOS&message=note&color=yellow)](https://github.com/abhinavsingh/proxy.py#user-content-flags) Also provide explicit CA bundle path needed for validation of peer certificates. See `--ca-file` flag.
973977

974978
Verify TLS interception using `curl`
975979

@@ -1042,7 +1046,8 @@ Important notes about TLS Interception with Docker container:
10421046
- Since `v2.2.0`, `proxy.py` docker container also ships with `openssl`. This allows `proxy.py`
10431047
to generate certificates on the fly for TLS Interception.
10441048

1045-
- For security reasons, `proxy.py` docker container doesn't ship with CA certificates.
1049+
- For security reasons, `proxy.py` docker container does not ship with
1050+
CA certificates.
10461051

10471052
Here is how to start a `proxy.py` docker container
10481053
with TLS Interception:
@@ -1329,9 +1334,9 @@ if __name__ == '__main__':
13291334

13301335
# Unit testing with proxy.py
13311336

1332-
## proxy.TestCase
1337+
## `proxy.TestCase`
13331338

1334-
To setup and teardown `proxy.py` for your Python `unittest` classes,
1339+
To setup and tear down `proxy.py` for your Python `unittest` classes,
13351340
simply use `proxy.TestCase` instead of `unittest.TestCase`.
13361341
Example:
13371342

@@ -1346,10 +1351,10 @@ class TestProxyPyEmbedded(proxy.TestCase):
13461351

13471352
Note that:
13481353

1349-
1. `proxy.TestCase` overrides `unittest.TestCase.run()` method to setup and teardown `proxy.py`.
1354+
1. `proxy.TestCase` overrides `unittest.TestCase.run()` method to setup and tear down `proxy.py`.
13501355
2. `proxy.py` server will listen on a random available port on the system.
13511356
This random port is available as `self.PROXY.acceptors.flags.port` within your test cases.
1352-
3. Only a single acceptor and worker is started by default (`--num-workers 1 --num-acceptors 1`) for faster setup and teardown.
1357+
3. Only a single acceptor and worker is started by default (`--num-workers 1 --num-acceptors 1`) for faster setup and tear down.
13531358
4. Most importantly, `proxy.TestCase` also ensures `proxy.py` server
13541359
is up and running before proceeding with execution of tests. By default,
13551360
`proxy.TestCase` will wait for `10 seconds` for `proxy.py` server to start,
@@ -1373,13 +1378,15 @@ class TestProxyPyEmbedded(TestCase):
13731378
self.assertTrue(True)
13741379
```
13751380

1376-
See [test_embed.py](https://github.com/abhinavsingh/proxy.py/blob/develop/tests/test_embed.py)
1377-
for full working example.
1381+
See [test_embed.py] for full working example.
1382+
1383+
[test_embed.py]:
1384+
https://github.com/abhinavsingh/proxy.py/blob/develop/tests/testing/test_embed.py
13781385

1379-
## With unittest.TestCase
1386+
## With `unittest.TestCase`
13801387

13811388
If for some reasons you are unable to directly use `proxy.TestCase`,
1382-
then simply override `unittest.TestCase.run` yourself to setup and teardown `proxy.py`.
1389+
then simply override `unittest.TestCase.run` yourself to setup and tear down `proxy.py`.
13831390
Example:
13841391

13851392
```python
@@ -1400,7 +1407,7 @@ class TestProxyPyEmbedded(unittest.TestCase):
14001407
super().run(result)
14011408
```
14021409

1403-
or simply setup / teardown `proxy.py` within
1410+
or simply setup / tear down `proxy.py` within
14041411
`setUpClass` and `teardownClass` class methods.
14051412

14061413
# Utilities
@@ -1438,7 +1445,7 @@ As a decorator:
14381445
>>> ... [ use connection ] ...
14391446
```
14401447

1441-
## Http Client
1448+
## HTTP Client
14421449

14431450
### build_http_request
14441451

@@ -1482,7 +1489,7 @@ build_http_response(
14821489

14831490
### API Usage
14841491

1485-
- gen_private_key
1492+
- `gen_private_key`
14861493

14871494
```python
14881495
gen_private_key(
@@ -1492,7 +1499,7 @@ build_http_response(
14921499
timeout: int = 10) -> bool
14931500
```
14941501

1495-
- gen_public_key
1502+
- `gen_public_key`
14961503

14971504
```python
14981505
gen_public_key(
@@ -1506,7 +1513,7 @@ build_http_response(
15061513
timeout: int = 10) -> bool
15071514
```
15081515

1509-
- remove_passphrase
1516+
- `remove_passphrase`
15101517

15111518
```python
15121519
remove_passphrase(
@@ -1516,7 +1523,7 @@ build_http_response(
15161523
timeout: int = 10) -> bool
15171524
```
15181525

1519-
- gen_csr
1526+
- `gen_csr`
15201527

15211528
```python
15221529
gen_csr(
@@ -1527,7 +1534,7 @@ build_http_response(
15271534
timeout: int = 10) -> bool
15281535
```
15291536

1530-
- sign_csr
1537+
- `sign_csr`
15311538

15321539
```python
15331540
sign_csr(
@@ -1640,7 +1647,7 @@ Visit dashboard:
16401647

16411648
Wait for embedded `Chrome Dev Console` to load. Currently, detail about all traffic flowing
16421649
through `proxy.py` is pushed to the `Inspect Traffic` tab. However, received payloads are not
1643-
yet integrated with the embedded dev console.
1650+
yet integrated with the embedded developer console.
16441651

16451652
Current functionality can be verified by opening the `Dev Console` of dashboard and inspecting
16461653
the websocket connection that dashboard established with the `proxy.py` server.
@@ -1782,7 +1789,7 @@ for some background.
17821789

17831790
## GCE log viewer integration for proxy.py
17841791

1785-
A starter [fluentd.conf](https://github.com/abhinavsingh/proxy.py/blob/develop/fluentd.conf)
1792+
A starter [fluentd.conf](https://github.com/abhinavsingh/proxy.py/blob/develop/helper/fluentd.conf)
17861793
template is available.
17871794

17881795
1. Copy this configuration file as `proxy.py.conf` under
@@ -1798,7 +1805,7 @@ template is available.
17981805
Now `proxy.py` logs can be browsed using
17991806
[GCE log viewer](https://console.cloud.google.com/logs/viewer).
18001807

1801-
## ValueError: filedescriptor out of range in select
1808+
## `ValueError: filedescriptor out of range in select`
18021809

18031810
`proxy.py` is made to handle thousands of connections per second
18041811
without any socket leaks.
@@ -1915,7 +1922,7 @@ the incoming client connections.
19151922

19161923
Each `Acceptor` process delegates the accepted client connection
19171924
to a threadless process via `Work` class. Currently, `HttpProtocolHandler`
1918-
is the default work klass.
1925+
is the default work class.
19191926

19201927
`HttpProtocolHandler` simply assumes that incoming clients will follow
19211928
HTTP specification. Specific HTTP proxy and HTTP server implementations

0 commit comments

Comments
 (0)