Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Middleware] Capability in the core to allow custom client connection classes #993

Merged
merged 7 commits into from
Jan 15, 2022

Conversation

abhinavsingh
Copy link
Owner

@abhinavsingh abhinavsingh commented Jan 15, 2022

This PR

  • Adds capability to the core so that a custom HttpClientConnection object can be shared with plugins instead of the current default TcpClientConnection.
  • Add integration tests for HTTPS web and proxy server

Agenda: All plugins must use client.response not client.queue

Using client.queue works but imposes challenges for outgoing response handling/customization/inspection. Instead all plugins must now call client.response. Internally, it works the same as client.queue. Just that now, plugins must queue a HttpParser, WebsocketFrame etc objects instead of memoryview or raw bytes.

By doing so it becomes possible for the core to provide a response based callback eco-system e.g. proxy plugins can modify/update responses queued by other plugins (currently only a single plugin can technically send response). Also, we'll be able to add middleware support for proxy and web server plugins.

Note that client.queue itself will continue to work. Just that such plugins will not be able to take advantage of core capabilities that will depend upon plugins use of client.response. At some point in far future, client.queue method will be made private.

…e the encryption functionality within TCP base server
@abhinavsingh abhinavsingh added the bot:chronographer:skip PR using this label is exempted from CHANGELOG management label Jan 15, 2022
@codecov
Copy link

codecov bot commented Jan 15, 2022

Codecov Report

Merging #993 (dc765e2) into develop (d17dc9e) will increase coverage by 0.51%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #993      +/-   ##
===========================================
+ Coverage    86.59%   87.11%   +0.51%     
===========================================
  Files          145      145              
  Lines         6261     6284      +23     
  Branches       626      626              
===========================================
+ Hits          5422     5474      +52     
+ Misses         725      705      -20     
+ Partials       114      105       -9     
Flag Coverage Δ
pytest 86.99% <100.00%> (+0.51%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
proxy/common/pki.py 100.00% <ø> (ø)
proxy/core/base/tcp_server.py 89.02% <100.00%> (+2.81%) ⬆️
proxy/core/base/tcp_tunnel.py 38.46% <100.00%> (ø)
proxy/http/handler.py 75.11% <100.00%> (+0.97%) ⬆️
proxy/plugin/web_server_route.py 82.35% <100.00%> (+11.76%) ⬆️
tests/common/test_pki.py 100.00% <100.00%> (ø)
tests/integration/test_integration.py 100.00% <100.00%> (ø)
proxy/core/work/threadless.py 82.62% <0.00%> (+1.87%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d17dc9e...dc765e2. Read the comment docs.

@abhinavsingh abhinavsingh changed the title [Plugin] All plugins must use client.response not client.queue [Middleware] All plugins must use client.response not client.queue Jan 15, 2022
@abhinavsingh abhinavsingh changed the title [Middleware] All plugins must use client.response not client.queue [Middleware] 1/N - All plugins must use client.response not client.queue Jan 15, 2022
@abhinavsingh abhinavsingh changed the title [Middleware] 1/N - All plugins must use client.response not client.queue [Middleware] Adds capability to the core to allow custom client connection classes Jan 15, 2022
@abhinavsingh abhinavsingh changed the title [Middleware] Adds capability to the core to allow custom client connection classes [Middleware] Capability in the core to allow custom client connection classes Jan 15, 2022
@abhinavsingh abhinavsingh marked this pull request as ready for review January 15, 2022 21:52
@abhinavsingh abhinavsingh merged commit c6fceb6 into develop Jan 15, 2022
@abhinavsingh abhinavsingh deleted the http-response-not-client-queue branch January 15, 2022 21:52
abhinavsingh added a commit that referenced this pull request Jan 20, 2022
* Fix README instructions for embedded mode

* Expose sleep_loop

* [SshTunnel] WIP (#992)

[SshTunnel] WIP

* [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 #994

* Fix docs

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

* [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

* Bail out early for non-HTTP but HTTP looking protocols (#972)

* Add support in `Url` to parse all types of schemes

* .

* Guard handler against http looking protocol but not web or proxy requests

* Fix condition for web server protocol detection

* doc happy

* Update flags and type check imports only

* npm: bump eslint-plugin-import from 2.25.3 to 2.25.4 in /dashboard (#1005)

Bumps [eslint-plugin-import](https://github.com/import-js/eslint-plugin-import) from 2.25.3 to 2.25.4.
- [Release notes](https://github.com/import-js/eslint-plugin-import/releases)
- [Changelog](https://github.com/import-js/eslint-plugin-import/blob/main/CHANGELOG.md)
- [Commits](import-js/eslint-plugin-import@v2.25.3...v2.25.4)

---
updated-dependencies:
- dependency-name: eslint-plugin-import
  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>

* npm: bump ws from 8.4.0 to 8.4.2 in /dashboard (#1007)

Bumps [ws](https://github.com/websockets/ws) from 8.4.0 to 8.4.2.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](websockets/ws@8.4.0...8.4.2)

---
updated-dependencies:
- dependency-name: ws
  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>

* Fix broken `--local-executor` logic for windows ever since it was made default (#1008)

Co-authored-by: sowmyasudhasingh <sowmyasudhasingh@gmail.com>

* [Windows] `--threaded` mode integration tests works locally but fails on GHA (#1009)

* Enable remote threadless and threaded integration test for windows

* Run only threaded on windows

* Use powershell for execution of integration script on Windows

* Update test_integration.py

* Update test_integration.py

Co-authored-by: sowmyasudhasingh <sowmyasudhasingh@gmail.com>
Co-authored-by: Abhinav Singh <126065+abhinavsingh@users.noreply.github.com>

* Restrict request handling to `DEFAULT_ALLOWED_URL_SCHEMES` (#1002)

* Raise `HttpProtocolException` if request line scheme do not match `DEFAULT_ALLOWED_URL_SCHEMES`

* ignore WPS329

* Fix tests

* Pin to 4.3.2

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

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

* Test coverage for exception handling

* type ignore

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

* [Doc] Threadless Remote vs Local Execution Mode (#1011)

* [Coverage] For newly added components (#1014)

* Add newly added code cov

* Fix spelling

* [Devtools] Build as part of GHA workflow (#1015)

* Fix devtools build

* Build devtools as part of GHA workflows

* [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>

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: Sowmya Sudha Singh <83529764+sowmya-jaxl@users.noreply.github.com>
Co-authored-by: sowmyasudhasingh <sowmyasudhasingh@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot:chronographer:skip PR using this label is exempted from CHANGELOG management
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant