Commit Graph

42 Commits

Author SHA1 Message Date
Abhinav Singh 2fa320d03f
Python 3.11 support (#1384)
* Changes for Python 3.11 support

* Updated README.md for versioning info

* Update `httpx==0.27.0` to avoid `cgi` deprecation warning from pytest on Python 3.11

* Make tests work for 3.11

* Declare support for 3.11

* Use 3.11-alpine for Docker images

* Preserve pylint version for `python_version <= 3.10`

* Preserve httpx version for <= 3.10

* `httpx` usage fix in tests for <=3.10

* Adjust pylint and pytest for >= 3.11

* Use 3.11.8, bad-option-value and httpx proxies fix

* tox for 3.11

* Fix for `TOXENV: py`

* -vv for pytest

* Downgrade to `pytest-asyncio==0.21.1`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove asyncio_mode=strict

* try with `pytest-cov==4.1.0` for 3.11

* bump coverage for 3.11

* Try `3.11` in GitHub workflow which installs >3.11.8 unavailable via pyenv yet

* Revert back to `-v`

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-04-13 13:22:25 +05:30
Abhinav Singh de36c6089b
[Examples] Fix broken examples (#1077)
* Fix broken examples

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix mypy

* Pylint ignore

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-30 18:30:54 +05:30
Abhinav Singh 4af0c2f601
[Task] A generic payload based work abstraction (#1057)
* Refactor into an internal task submodule of work

* As context managers

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add missing license

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-25 01:51:41 +05:30
Abhinav Singh d1920460d0
Pre `v2.4.0rc8` cleanups (#1053)
* Pre-release cleanups

* Add listener pool test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add multi listener test

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-24 11:36:51 +05:30
Abhinav Singh 2bebbacbd3
[Work] `kwargs` independent `work_klass` creation and work core (#1051)
* `kwargs` independent work klass and core

* Fix tests

* Add a `create` method to base class

* Lint fixes
2022-01-24 03:16:08 +05:30
Abhinav Singh 54e74a911f
[isort] Lib modules (#1016)
* isort `proxy.py` main class

* isort init and main

* isort common

* pre-commit fix

* isort dashboard and testing

* isort plugins

* isort core

* Only sort top level http py files

* isort http exception and websocket

* Remove proxy auth plugin from proxy package exports and force discover `PLUGIN_PROXY_AUTH` flags

* isort parser and web server

* no setattr

* isort all

* Enable pre-commit isort hook

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-20 15:34:54 +05:30
Abhinav Singh 7beef281c6
[Coverage] For newly added components (#1014)
* Add newly added code cov

* Fix spelling
2022-01-20 11:45:29 +05:30
Abhinav Singh 552fb998df
[Middleware] `HttpClientConnection` preparation (#995)
* Turn usual suspects to warnings, not error

* Add `HttpClientConnection` skeleton

* Fix doc build

* Update references in http tests

* Make `work` core agnostic to work object construction by adding an abstract static method to `Work` interface called `create`

* Make mypy happy

* Fix tests broken due to change in how work objects are now constructed

* Doc ko bhi happy karo
2022-01-16 18:34:33 +05:30
Abhinav Singh c6fceb639a
[Middleware] Capability in the core to allow custom client connection classes (#993)
* Move all TCP server related flags within `tcp_server.py` and also move the encryption functionality within TCP base server

* Templatize `BaseTcpServerHandler` which now expects a client connection object bound to `TcpClientConnection`.  This will allow for custom `HttpClientConnection` object in future to be used by `HttpProtocolHandler`

* Pass necessary flags to allow self-signed certificates

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix https integration tests

* Affected by https://github.com/abhinavsingh/proxy.py/issues/994

* Fix docs

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-16 03:22:55 +05:30
Abhinav Singh dd2476f02a
Refactor into separate `Work` module (#977)
* work module

* Fix imports

* String based typing for multiprocessing.synchronize

* Fix `test_accepts_client_from_server_socket`

* Move staticmethod outside of threadless pool class

* Fix doc build

* Fix test mock

* mp grouped together

* pylint happy

* import only for type checking

* doc build

* wrong import order
2022-01-13 16:07:51 +05:30
Abhinav Singh 35e9c57af7
`isort` everything except lib (for now) (#952)
* isort the tests folder

* Carry over changes from #672

* Disable pre-commit

* Revert flake8 config change

* isort examples too
2022-01-10 13:28:22 +05:30
Abhinav Singh 0d1fe198d3
`DescriptorsHandlerMixin` and `Descriptors`, `SelectableEvents` types (#938)
* Add `Descriptors` type

* Add a `DescriptorsHandlerMixin` class used throughout the http framework

* Remove dependency upon `HasFileno` ie `typing_extension` too

* Define `SelectableEvents` type

* Fix doc

* Blank line

* Remove dep on `typing-extensions`

* Discover base plugin class

* await on now async handlers
2022-01-05 00:32:16 +05:30
Abhinav Singh f921f56803
`Work` can also be `TcpServerConnection`, not just `TcpClientConnection` (#906)
* Work can also be TcpServerConnection, not just TcpClientConnection.  More over, it can be any generic work type

* Add py_class_role and py_obj

* Port internal integration tests into public repo

* Fix proxy py addr

* Use cross-platform compat shasum
2021-12-26 20:51:31 +05:30
Abhinav Singh c936f7e52d
Response Packet Utilities (#903)
* Add response pkt utility

* Unused import

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix tests as some content is now by default gzipped based upon min compression config

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove unused

* Update necessary tests to use `okResponse` utility

* Add option to explicitly disable compression

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-12-25 00:30:40 +05:30
Abhinav Singh 37c779ade9
Add `conn_close` kwarg to packet builder utilities (#898)
* Add `conn_close` kwarg to packet builder utilities, passing True will automatically add `Connection: close` header

* Add `conn_close` to `HttpRequestRejected` responses
2021-12-22 02:56:52 +05:30
Abhinav Singh 009935b29b
v2.4.0rc3 (#882)
* Merge pull request #840 from abhinavsingh/release-schedule-notes

Add release schedule under FAQ

* Green CI (#841)

* Cleanup parser & url classes (#843)

* Optimize parser logic

* Add `is_complete` property

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* pre commit fixes

* We need `ValueError`

* wuff

* useless

* flake8

* Simplify url

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* pip prod(deps): bump twine from 3.6.0 to 3.7.0 (#845)

Bumps [twine](https://github.com/pypa/twine) from 3.6.0 to 3.7.0.
- [Release notes](https://github.com/pypa/twine/releases)
- [Changelog](https://github.com/pypa/twine/blob/main/docs/changelog.rst)
- [Commits](https://github.com/pypa/twine/compare/3.6.0...3.7.0)

---
updated-dependencies:
- dependency-name: twine
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump jasmine from 3.6.3 to 3.10.0 in /dashboard (#844)

Bumps [jasmine](https://github.com/jasmine/jasmine-npm) from 3.6.3 to 3.10.0.
- [Release notes](https://github.com/jasmine/jasmine-npm/releases)
- [Commits](https://github.com/jasmine/jasmine-npm/compare/v3.6.3...v3.10.0)

---
updated-dependencies:
- dependency-name: jasmine
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com>

* npm: bump chrome-devtools-frontend in /dashboard (#846)

Bumps [chrome-devtools-frontend](https://github.com/ChromeDevTools/devtools-frontend) from 1.0.944903 to 1.0.947377.
- [Release notes](https://github.com/ChromeDevTools/devtools-frontend/releases)
- [Changelog](https://github.com/ChromeDevTools/devtools-frontend/blob/main/docs/release_management.md)
- [Commits](https://github.com/ChromeDevTools/devtools-frontend/commits)

---
updated-dependencies:
- dependency-name: chrome-devtools-frontend
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* pip prod(deps): bump coverage from 6.1.2 to 6.2 (#847)

Bumps [coverage](https://github.com/nedbat/coveragepy) from 6.1.2 to 6.2.
- [Release notes](https://github.com/nedbat/coveragepy/releases)
- [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
- [Commits](https://github.com/nedbat/coveragepy/compare/6.1.2...6.2)

---
updated-dependencies:
- dependency-name: coverage
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com>

* Fix GHA check-gate to properly identify failures (#849)

* pip prod(deps): bump pylint from 2.12.1 to 2.12.2 (#851)

Bumps [pylint](https://github.com/PyCQA/pylint) from 2.12.1 to 2.12.2.
- [Release notes](https://github.com/PyCQA/pylint/releases)
- [Changelog](https://github.com/PyCQA/pylint/blob/main/ChangeLog)
- [Commits](https://github.com/PyCQA/pylint/compare/v2.12.1...v2.12.2)

---
updated-dependencies:
- dependency-name: pylint
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump @types/js-cookie from 2.2.6 to 3.0.1 in /dashboard (#850)

Bumps [@types/js-cookie](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/js-cookie) from 2.2.6 to 3.0.1.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/js-cookie)

---
updated-dependencies:
- dependency-name: "@types/js-cookie"
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com>

* pip prod(deps): bump sphinx from 4.3.0 to 4.3.1 (#853)

Bumps [sphinx](https://github.com/sphinx-doc/sphinx) from 4.3.0 to 4.3.1.
- [Release notes](https://github.com/sphinx-doc/sphinx/releases)
- [Changelog](https://github.com/sphinx-doc/sphinx/blob/4.x/CHANGES)
- [Commits](https://github.com/sphinx-doc/sphinx/compare/v4.3.0...v4.3.1)

---
updated-dependencies:
- dependency-name: sphinx
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* pip prod(deps): bump paramiko from 2.8.0 to 2.8.1 (#855)

* npm: bump ws from 7.4.6 to 8.3.0 in /dashboard (#854)

* pip prod(deps): bump uvicorn from 0.15.0 to 0.16.0 (#857)

Bumps [uvicorn](https://github.com/encode/uvicorn) from 0.15.0 to 0.16.0.
- [Release notes](https://github.com/encode/uvicorn/releases)
- [Changelog](https://github.com/encode/uvicorn/blob/master/CHANGELOG.md)
- [Commits](https://github.com/encode/uvicorn/compare/0.15.0...0.16.0)

---
updated-dependencies:
- dependency-name: uvicorn
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump chrome-devtools-frontend in /dashboard (#856)

Bumps [chrome-devtools-frontend](https://github.com/ChromeDevTools/devtools-frontend) from 1.0.947377 to 1.0.949424.
- [Release notes](https://github.com/ChromeDevTools/devtools-frontend/releases)
- [Changelog](https://github.com/ChromeDevTools/devtools-frontend/blob/main/docs/release_management.md)
- [Commits](https://github.com/ChromeDevTools/devtools-frontend/commits)

---
updated-dependencies:
- dependency-name: chrome-devtools-frontend
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com>

* Process `--enable-*` flags before loading plugins (#860)

* Process `--enable-*` flags before loading plugins

* Fix spelling

* Ignore RST299 and RST499

* npm: bump http-server from 0.12.3 to 14.0.0 in /dashboard (#858)

Bumps [http-server](https://github.com/http-party/http-server) from 0.12.3 to 14.0.0.
- [Release notes](https://github.com/http-party/http-server/releases)
- [Commits](https://github.com/http-party/http-server/compare/v0.12.3...v14.0.0)

---
updated-dependencies:
- dependency-name: http-server
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com>

* pip prod(deps): bump furo from 2021.11.15 to 2021.11.23 (#859)

Bumps [furo](https://github.com/pradyunsg/furo) from 2021.11.15 to 2021.11.23.
- [Release notes](https://github.com/pradyunsg/furo/releases)
- [Changelog](https://github.com/pradyunsg/furo/blob/main/docs/changelog.md)
- [Commits](https://github.com/pradyunsg/furo/compare/2021.11.15...2021.11.23)

---
updated-dependencies:
- dependency-name: furo
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com>

* Update web log context fields to match proxy log context fields (#861)

* Update web log context fields to match those with proxy log context for consistency

* Fix spell

* Fix `DEFAULT_WEB_ACCESS_LOG_FORMAT`

* pip prod(deps): bump pytest-xdist from 2.4.0 to 2.5.0 (#864)

Bumps [pytest-xdist](https://github.com/pytest-dev/pytest-xdist) from 2.4.0 to 2.5.0.
- [Release notes](https://github.com/pytest-dev/pytest-xdist/releases)
- [Changelog](https://github.com/pytest-dev/pytest-xdist/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest-xdist/compare/v2.4.0...v2.5.0)

---
updated-dependencies:
- dependency-name: pytest-xdist
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* npm: bump eslint-plugin-node from 10.0.0 to 11.1.0 in /dashboard (#863)

Bumps [eslint-plugin-node](https://github.com/mysticatea/eslint-plugin-node) from 10.0.0 to 11.1.0.
- [Release notes](https://github.com/mysticatea/eslint-plugin-node/releases)
- [Commits](https://github.com/mysticatea/eslint-plugin-node/compare/v10.0.0...v11.1.0)

---
updated-dependencies:
- dependency-name: eslint-plugin-node
  dependency-type: direct:development
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com>

* Fix broken TLS interception  & CacheResponsesPlugin because UID is no longer a UUID (#866)

* Fix broken TLS interception because uid is now no longer a UUID

* Give enough context to work id for them to be unique within a `proxy.py` instance

* Use --port=0 by default within `proxy.TestCase`

* Attempt to fix weird buildx issue

* Add makefile targets within workflow

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Order?

* Write scm file for make

* Fetch depth

* Quote patch

* Try with sudo?

* https://github.com/docker/buildx/issues/850

* Remove sudo hack

* https://github.com/docker/buildx/issues/850\#issuecomment-973270625

* Add explicit deps

* Add `requirements-testing.txt` during linting phase

* Pin buildx to v0.7.1

* Pin buildx to v0.7.0

* Revert back unnecessary change to dockerignore

* Skip container within make workflow (because GHA lacks support for docker on macOS by default)

* Repurpose make into developer workflow

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Integrate showing unreleased changelog draft (#873)

* pip prod(deps): bump types-paramiko from 2.8.2 to 2.8.4 (#868)

* npm: bump @types/jasmine from 3.6.1 to 3.10.2 in /dashboard (#867)

* pip prod(deps): bump py-spy from 0.3.10 to 0.3.11 (#875)

Bumps [py-spy](https://github.com/benfred/py-spy) from 0.3.10 to 0.3.11.
- [Release notes](https://github.com/benfred/py-spy/releases)
- [Changelog](https://github.com/benfred/py-spy/blob/master/CHANGELOG.md)
- [Commits](https://github.com/benfred/py-spy/compare/v0.3.10...v0.3.11)

---
updated-dependencies:
- dependency-name: py-spy
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com>

* [GHA] Add container integration test & publish containers to GHCR (#818)

* Handle KBI in threadless

* Remove line-length disable clause

* Move `Set PROXYPY_CONTAINER_VERSION env` within pre-setup

* Use step output

* Use review suggestion

* Break line at less essential places

* Possibly fix?

* alignment necessary?

* :)

* Fix integration

* Add `v` prefix

* Load buildx image within docker for integration tests to work

* Run container in detached mode

* Enable web server for integration test to work

* Push to GHCR after successful tests

* Tag & Push to GHCR

* Add package permission

* Login to GHCR

* Login to GHCR

* Login to GHCR

* Explicitly use ghcr.io registry

* Add a ghcr manifest creation step which depends upon docker step

* Probably we need all images (tags) locally

* arm not amd

* Fix syntax

* Fix typo

* `Unable to find image ghcr.io/abhinavsingh/proxy.py:latest locally`

* GHCR doesnt support manifest?

* Publish multi-platform containers on GHCR (#877)

* Build containers without matrix based strategy. Helps with buildx based manifest generation

* Use buildx directly in workflows

* Add PROXYPY_PKG_PATH arg

* Add missing .

* --push from buildx

* Also add latest tag for GHCR

* Fix typo

* Explain differences between latest tag on DockerHub (stable) and GHCR (develop)

* Publish multi-platform containers to DockerHub (#878)

* Use `--local-executor` flag by default for Docker container (#880)

* Benchmark gets packaged within wheel if set as a package

* Use `--local-executor` flag by default for Docker containers

* Dockerfile update

* Fix mypy issues

* Remove conflicting dir names

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sviatoslav Sydorenko <wk@sydorenko.org.ua>
2021-12-19 21:30:43 +05:30
Abhinav Singh 921f2b56e0
Optimizations & Update Benchmark Results (#832)
* Bail out of lock earlier

* Avoid calling `get_events` for unfinished work tasks.  Use `cached_property` for `HttpParser` optimization

* Add `type: ignore[no-any-return]`, odd scenario

* We dont have to rebuild response packet repeatedly within `WebServerPlugin`

* Parse line and header in one invocation

* Minor optimizations and update benchmark to use `oha` instead of `hey`

* Remove `flask` from benchmark, only benchmark `asgi` or `async` based libraries.  Use `uvicorn` and 10 workers for `blacksheep`.  Use `oha` instead of `hey`

* Add benchmark for `starlette`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add missing dep

* pre-commit

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-12-01 04:18:49 +05:30
Abhinav Singh 68df66fed5
Add `benchmark` results to `README.md` (#828)
* Add benchmark results to top-level README

* mypy

* Push down WIP example

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Spelling

* Link rtfd within `Internal Documentation` for now

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-30 00:10:04 +05:30
Abhinav Singh 44d72431e3
Async `get_events`, `handle_event`, `handle_readables`, `handle_writables` (#769)
* Asynchronous `handle_event` and `LocalExecutor` thread

* Bail out on first task completion

* mypy

* Add `helper/benchmark.sh` and fix threaded which must now use asyncio (reduced performance of threaded)

* Print open file diff from `benchmark.sh`

* Add `--local-executor` flag, disabled by default for now until tests are updated

* Async `handle_readables` and `handle_writables` for `HttpProtocolHandlerPlugin` interface (doesnt impact proxy/web plugins for now)

* Async `get_events`

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Address tests after async changes

* mypy and flake8

* spelldoc

* `check.py` and trailing comma

* Rename to `_assertions.py`

* Add missing `pytest-mock` and `pytest-asyncio` deps

* Add `pytest-mock` to `pylint` deps

* Correct use of `parameterize` and add `PT007` to flake8 ignores

* Fix mypy hints broken for `< Python3.9`

* Remove usage of `asynccontextmanager` which is not available for all Python versions that `proxy.py` supports

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix for pre-python-3.9 versions

* `AsyncTask` apis `set_name` and `get_name` are not available on all supported versions

* Install setuptools via `lib-dep` until we recommend editable install

* Deprecate support for `Python 3.6`

* Use recommendation suggested here https://github.com/abhinavsingh/proxy.py/pull/769\#discussion_r753840929

* Address recommendation here https://github.com/abhinavsingh/proxy.py/pull/769\#discussion_r753841906

* Make `Threadless` agnostic of `multiprocessing.Process`

* Acceptors must dispatch to local executor in non-blocking fashion

* No daemon for executor processes and fix shutdown logic

* Only return fds from `_selected_events` not all events data

* Refactor logic

* Prefix private methods with `_`

* `work_queue` and not `client_queue`

* Turn `Threadless` into an abstract executor. Introduce `RemoteExecutor`

* Make `LocalExecutor` agnostic of `threading.Thread`

* `LocalExecutor` now implements `Threadless`

* `get_events` and `get_descriptors` now must return int and not sock.  `Threadless` now avoids repeated register/unregister and instead make use of `selectors.modify`

* Fix `main` tests

* Apply suggestions from code review

Co-authored-by: Sviatoslav Sydorenko <wk@sydorenko.org.ua>

* Apply code review recommendations manually

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Revert back `Any` and use `addr or None`

* Address `flake8`

* Update tests to use `fileno`

* Fix doc build

* Fix doc spell, use tear down and not teardown

* Doc updates

* Add back support for `Python 3.6`

* Acceptors dont need loop initialization

* On Python 3.6 `asyncio.new_event_loop()` is necessary

* Make doc happy

* `--threaded` needs a new event loop for 3.7 too

* Always use `asyncio.new_event_loop()` for threaded mode

Added e2e integration tests (subprocess & curl) for all modes.

* Lint fixes

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Sviatoslav Sydorenko <wk@sydorenko.org.ua>
2021-11-23 15:02:00 +05:30
Abhinav Singh 7f1470e3a9
No abstract method for proxy plugin (#738)
* Remove abstractmethod for proxy plugin base class, remove unused methods from bundled plugins

* Move httpStatusCodes, httpMethods and Url within top-level proxy.http package
2021-11-15 03:17:12 +05:30
Abhinav Singh 541da114c8
Custom Url Parser (#730)
* Custom Url parser for our needs

* lint fix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix proxy_pool plugin as scheme can be None if not present in the Url

* Address the ambiguous ipv6:port scenario along with valid cases

* lint checks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* docstring

* Abstract into `http.parser` module

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix #398 HTTP/1.0 related issue

* lint checks

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-12 19:00:19 +05:30
Abhinav Singh ddf90fb6f0
Allow `--plugins` flag to be used multiple times (#725)
* deprecate server_file_or_404

* Optionally compress static content.  Currently only if content length higher than 300

* trailing comma

* Allow `--plugins` flag to be used multiple times

Following are valid invocation:
1) `--plugins A`
2) `--plugins A,B`
3) `--plugins A --plugins B`
4) `--plugins A,B --plugins C`

* mypy

* Flake8

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* correct type

* Add `HttpParser.is_https_tunnel()` utility method

* mypy

* lint checks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-12 02:46:43 +05:30
Abhinav Singh df7f1c887b
Add `Listener`, Web server close on header, use `Pipe` instead of `Manager` in eventing core (#720)
* Abstract out a Listener class

* unused

* Use connection instead of manager queue

* For web close connection of client requested via headers

* Remove eventing WIP module

* Sub and Unsub ack

* Fix tests

* mypy and flake8

* comma

* Move callback within EventSubscriber constructor

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Skip test_unix_path_listener on Windows

* Spelling fix

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-10 20:47:28 +05:30
Abhinav Singh 0a038ce8be
Add `--num-acceptors` flag + Allow `work_klass` via `Proxy` context manager kwargs (#714)
* Allow overriding work_klass via Proxy context manager kwargs

* Decouple acceptor and executor pools

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add `--num_acceptors` flag and better load balancing

* Remove unused

* Lint errors

* Another arg not kwarg

* Move start work staticmethods within ExecutorPool

* mypy fixes

* Update README with `--num-acceptors` flag

* Rename `Proxy.pool` to `Proxy.acceptors`

* Add SetupShutdownContextManager abstraction

* Match --num-acceptors logic with PR description

* Rename executor utility methods and add docstring

* Remove work_klass from constructors and pass it via flags

* Update docstring for pools as they no longer accept a work_klass argument

* Turn work_klass into a flag.  main() no longer accepts input_args (only kwargs opts).  Similarly, Proxy doesnt accept any input_args now (only kwargs opts)

* Expose default work klass in README

* Expose `HttpProtocolHandler` and `HttpProtocolHandlerPlugin` within `proxy.http` module

* Start to fix tests

* Fix tests

* mypy and flake8

* Trailing comma

* Remove unused var

* Unused arg

* uff

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-10 04:27:40 +05:30
Abhinav Singh aadcc10813
`EventManager` is also a context manager (#709)
* `EventManager` is also a context manager

* unused

* Rename `EventManager.event_queue` to `EventManager.queue`
2021-11-08 23:02:36 +05:30
Abhinav Singh a8e3966525
Put core flags where they belong (#702)
* Move flags to where they belong

* Move `get_default_plugins` within FlagParser as it depends upon args

TODO: We need plugin dependency system

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-08 03:21:42 +05:30
Abhinav Singh 3cb0a62583
Add a `--unix-socket-path` flag (#697)
* Add a `--unix-socket-path` flag.

When available `--hostname` and `--port` flags are ignored.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* `print` statement is allowed only in `flags.py` and `version-check.py`.  All other places must use a `logger` instance

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add guard for `AF_UNIX` on Windows

* Comment out assertion on Windows for now

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-08 01:11:46 +05:30
Abhinav Singh b830f7b238
Rename `Proxy.initialize` as `FlagParser.initialize` (#696)
* Move Proxy.initialize within FlagParser.initialize.  Also move other staticmethods from within proxy class into utils

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove unused imports

* Fix `import-outside-toplevel` error

* add `make lib-flake8` and `make lib-mypy` targets

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-07 23:02:34 +05:30
Abhinav Singh f48771fb41
Top-level notion of work not client (#695)
* Top-level notion of work not client

* Update ssl echo server example
2021-11-07 21:43:38 +05:30
Abhinav Singh d3cee32909
Pool (#694)
* Refactor pool

* mypy fixes

* Fix import (relative)

* Add WebScraper example skeleton & ConnectionPool skeleton

* Add ConnectionPool class

* Integrate ConnectionPool with proxy server (experimental)

* Lint fixes

* Remove unused imports. TODO: Put pool behind a flag. Default to false for now

* Make ConnectionPool multiprocess safe.  Later we want to make it safe but without using locks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove unused imports

* Return created flag from acquire

* Guard connection pool behind --enable-conn-pool flag

* Flag belongs within connection pool class

* spelling

* self.upstream = None only for pool config

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-07 21:06:41 +05:30
Abhinav Singh 628de71ca8
Adopt BaseTcpServerHandler within HttpProtocolHandler (#681)
* Rename .server to .upstream

* Lint fixes

* Mark internal methods with _ prefix

* Fix broken test

* lint changes

* Wah, double client :D

* Avoid selector initialization for threadless mode

* remove unused imports

* Now HttpProtocolHandler implements BaseTcpServerHandler

* Consistent return and guard againt upstream.closed

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* AcceptorPool as context manager

* Group multiprocessing imports together

* Use com.jaxl bundle identifier as proxy.py will eventually move under jaxl org

* revisit devtools integration :)

* Emit all necessary events for devtools integration

* Lint fixes

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-06 14:01:13 +05:30
Sviatoslav Sydorenko 05a78567ac
Enable the `add-trailing-comma` pre-commit fixer (#661)
Co-authored-by: Abhinav Singh <mailsforabhinav@gmail.com>
2021-11-04 16:58:36 +05:30
Abhinav Singh d4ee4fa15c
Async proxy pool, Event manager, Custom access log, Expose loop to plugins (#645)
* Async proxy pool

* Async proxy pool

* Late upstream initialization and exception guards

* Close upstream proxy connection on client connection close

* Refactor into EventManager

* Fix tests accounting in the event manager

* Ensure each process initializes logger

* pragma no cover

* Teardown connection when proxy pool upstream proxy closes

* Add ability to customize access log format and add additional context to it

* Maintain total size for response bytes in access logs

* Fix tests broken due to new plugin methods missing mock

* Update pubsub_eventing to use EventManager to avoid entire bootstrapping step
2021-11-01 01:19:19 +05:30
Abhinav Singh 4520ae31a6
Refactor base server interfaces into core modules (#461)
* Ensure pending buffers are flushed before shutting down in base_server.py

Handle unsupported scheme cases within connect_tunnel.py

* Move base implementations within core module

* Update ssl_echo_server
2020-11-24 21:37:11 +05:30
Abhinav Singh 0744cd8e7f
Go flagless to allow custom user defined flags. (#452)
* Go flagless to allow custom user defined flags. Fixes #301

* Add --cache-dir flag for cache plugin (when used with on-disk store)

* Enable discovery of flags from external plugins, example those that reside outside of proxy.py package and loaded on demand.  This also allows external flags to surface in --help section

* Define --filtered-client-ips flag for FilterByClientIpPlugin
2020-10-14 10:51:56 +05:30
Abhinav Singh 4804c534f8
Update mypy (#449) 2020-10-10 16:23:29 +05:30
Abhinav Singh 1038bb841d
More examples (#444)
* Refactor into BaseServerHandler and BaseEchoServerHandler classes

* Add connect tunnel example
2020-10-06 22:27:19 +05:30
Abhinav Singh 1867d58338
Add cross ref for how to generate SSL certs. (#401) 2020-07-12 21:24:20 +05:30
Abhinav Singh 73bcf1d057
Add core pubsub eventing example and add menubar item skeleton (#396)
* Initialize menu bar items with click handler and open a popover for preferences

* Add Core PubSub eventing example

* Remove hardcoded request ids
2020-07-09 21:31:29 +05:30
Abhinav Singh b7c4c5f175
Add SSL echo server & client example (#395)
* Move wrap_socket for SSL server within utils.

Also complete proxy.common.pki gen_csr and sign_csr actions. Used by Makefile sign-https-certificates.

* Add SSL echo server and client example

* Add examples documentation
2020-07-08 16:38:58 +05:30
Abhinav Singh 682114e9e0
Decouple SSL wrap logic into connection classes (#394)
* Move wrap functionality within respective connection classes. Also decouple websocket client handshake method

* Add a TCP echo client example that works with TCP echo server example
2020-07-08 13:11:12 +05:30
Abhinav Singh c884338f42
Core acceptor pool doc, cleanup and standalone example (#393)
* Better document acceptor module and add a TCP Echo Server example

* autopep8 formating

* Rename ThreadlessWork --> Work class

* Make initialize, is_inactive and shutdown as optional interface methods.

Also introduce Readables & Writables custom types.

* Move websocket code into its own module

* Add websocket client example

* Cleanup websocket client
2020-07-07 18:01:49 +05:30