You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Remove autopep8, is redundant now after recent CI changes
* Add pyenv .python-version to .gitignore
* Update year
* Add lib-pytest target so that pytest can run in isolation
* Add git-push hook which will also run the lint.
By default now git-pre-commit hook will only run pytest.
* Update outdated sections of README
* Update requirement to match setup.cfg install_requires
* Deprecate proxy.start and TestCase.PROXY_PORT
Proxy port during test is now available as self.PROXY.pool.flags.port.
Also now TestCase utilize ephemeral port strategy instead of
calling get_available_port utility method.
* Rename to git-pre-push
* Ideally public repo dont require CODECOV_TOKEN but codecov integration is broken since introduction of codecov-action@v2 (instead of codecov binary invocation)
* Issue is possibly with codecov@v2 action, fallback to codecov. See https://github.com/abhinavsingh/proxy.py/runs/4110423084\?check_suite_focus\=true and codecov/uploader#223
* Revert back to v2
@@ -1149,24 +1149,40 @@ by using `start` method: Example:
1149
1149
import proxy
1150
1150
1151
1151
if __name__ == '__main__':
1152
-
with proxy.start([]):
1152
+
with proxy.Proxy([]) as p:
1153
1153
# ... your logic here ...
1154
1154
```
1155
1155
1156
1156
Note that:
1157
1157
1158
-
1. `start` is similar to `main`, except `start` won't block.
1159
-
1. `start` is a context manager.
1158
+
1. `Proxy` is similar to `main`, except `Proxy` does not block.
1159
+
1. Internally `Proxy` is a context manager.
1160
1160
It will start `proxy.py` when called and will shut it down
1161
-
once scope ends.
1162
-
1. Just like `main`, startup flags with `start` method
1161
+
once the scope ends.
1162
+
1. Just like `main`, startup flags with `Proxy`
1163
1163
can be customized by either passing flags as list of
1164
-
input arguments e.g. `start(['--port', '8899'])` or
1165
-
by using passing flags as kwargs e.g. `start(port=8899)`.
1164
+
input arguments e.g. `Proxy(['--port', '8899'])` or
1165
+
by using passing flags as kwargs e.g. `Proxy(port=8899)`.
1166
+
1167
+
## Ephemeral Port
1168
+
1169
+
Use `--port=0` to bind `proxy.py` on a random port allocated by the kernel.
1170
+
1171
+
In embedded mode, you can access this port. Example:
1172
+
1173
+
```python
1174
+
import proxy
1175
+
1176
+
if __name__ == '__main__':
1177
+
with proxy.Proxy([]) as p:
1178
+
print(p.pool.flags.port)
1179
+
```
1180
+
1181
+
`pool.flags.port` will give you access to the random port allocated by the kernel.
1166
1182
1167
1183
## Loading Plugins
1168
1184
1169
-
You can, of course, list plugins to load in the input arguments list of `proxy.main`, `proxy.start`or the `Proxy` constructor. Use the `--plugins` flag as when starting from command line:
1185
+
You can, of course, list plugins to load in the input arguments list of `proxy.main`or `Proxy` constructor. Use the `--plugins` flag when starting from command line:
1170
1186
1171
1187
```python
1172
1188
import proxy
@@ -1177,7 +1193,7 @@ if __name__ == '__main__':
1177
1193
])
1178
1194
```
1179
1195
1180
-
However, forsimplicity you can pass the list of plugins to load as a keyword argument to `proxy.main`, `proxy.start` or the `Proxy` constructor:
1196
+
For simplicity you can pass the list of plugins to load as a keyword argument to `proxy.main` or the `Proxy` constructor:
1181
1197
1182
1198
```python
1183
1199
import proxy
@@ -1193,20 +1209,19 @@ if __name__ == '__main__':
1193
1209
Note that it supports:
1194
1210
1195
1211
1. The fully-qualified name of a class as `bytes`
1196
-
2. Any `type` instance for a Proxy.py plugin class. This is especially useful forcustom plugins defined locally.
1212
+
2. Any `type` instance of a plugin class. This is especially useful for plugins defined at runtime
1197
1213
1198
1214
# Unit testing with proxy.py
1199
1215
1200
1216
## proxy.TestCase
1201
1217
1202
-
To setup and teardown `proxy.py`for your Python unittest classes,
1218
+
To setup and teardown `proxy.py` for your Python `unittest` classes,
1203
1219
simply use `proxy.TestCase` instead of `unittest.TestCase`.
1204
1220
Example:
1205
1221
1206
1222
```python
1207
1223
import proxy
1208
1224
1209
-
1210
1225
class TestProxyPyEmbedded(proxy.TestCase):
1211
1226
1212
1227
def test_my_application_with_proxy(self) -> None:
@@ -1217,7 +1232,7 @@ Note that:
1217
1232
1218
1233
1. `proxy.TestCase` overrides `unittest.TestCase.run()` method to setup and teardown `proxy.py`.
1219
1234
2. `proxy.py` server will listen on a random available port on the system.
1220
-
This random port is available as `self.PROXY_PORT` within your test cases.
1235
+
This random port is available as `self.PROXY.pool.flags.port` within your test cases.
1221
1236
3. Only a single worker is started by default (`--num-workers 1`) for faster setup and teardown.
1222
1237
4. Most importantly, `proxy.TestCase` also ensures `proxy.py` server
1223
1238
is up and running before proceeding with execution of tests. By default,
@@ -1272,52 +1287,63 @@ or simply setup / teardown `proxy.py` within
1272
1287
1273
1288
# Plugin Developer and Contributor Guide
1274
1289
1275
-
## Everything is a plugin
1276
-
1277
-
As you might have guessed by now, in`proxy.py` everything is a plugin.
1290
+
## High level architecture
1278
1291
1279
-
- We enabled proxy server plugins using `--plugins` flag.
1280
-
All the [plugin examples](#plugin-examples) were implementing
for available lifecycle hooks. Use `HttpProxyBasePlugin` to modify
1284
-
behavior of http(s) proxy protocol between client and upstream server.
1285
-
Example, [FilterByUpstreamHostPlugin](#filterbyupstreamhostplugin).
1286
-
1287
-
- We also enabled inbuilt web server using `--enable-web-server`.
1288
-
Inbuilt web server implements `HttpProtocolHandlerPlugin` plugin.
1289
-
See documentation of [HttpProtocolHandlerPlugin](https://github.com/abhinavsingh/proxy.py/blob/b03629fa0df1595eb4995427bc601063be7fdca9/proxy.py#L793-L850)
1290
-
for available lifecycle hooks. Use `HttpProtocolHandlerPlugin` to add
thread is started with the accepted [TcpClientConnection](https://github.com/abhinavsingh/proxy.py/blob/b03629fa0df1595eb4995427bc601063be7fdca9/proxy.py#L230-L237).
1303
-
`HttpProtocolHandler` is responsible for parsing incoming client request and invoking
1304
-
`HttpProtocolHandlerPlugin` lifecycle hooks.
1328
+
Within `proxy.py` everything is a plugin.
1305
1329
1306
-
- `HttpProxyPlugin` which implements `HttpProtocolHandlerPlugin` also has its own plugin
1307
-
mechanism. Its responsibility is to establish connection between client and
- We enabled `proxy server` plugins using `--plugins` flag.
1331
+
Proxy server `HttpProxyPlugin` is a plugin of `HttpProtocolHandler`.
1332
+
Further, Proxy server allows plugin through `HttpProxyBasePlugin` specification.
1310
1333
1311
-
- `HttpProtocolHandler` threads are started by [Acceptor](https://github.com/abhinavsingh/proxy.py/blob/b03629fa0df1595eb4995427bc601063be7fdca9/proxy.py#L424-L472)
1312
-
processes.
1334
+
- All the proxy server [plugin examples](#plugin-examples) were implementing
1335
+
`HttpProxyBasePlugin`. See documentation of `HttpProxyBasePlugin` for available
1336
+
lifecycle hooks. Use `HttpProxyBasePlugin` to modify behavior of http(s) proxy protocol
0 commit comments