Commit Graph

15 Commits

Author SHA1 Message Date
Abhinav Singh 99fc17b2a3
Optimize (#780)
* Optimize `find_http_line` which is in critical path

* Update benchmark results

* Keep the loop hot, TCP no delay, cleanup inactive check periodically

* Check for shutdown signal with tick

* Use non-reentrant `NonBlockingQueue` implementation instead of `queue.Queue`

* Fix listener test

* lint and doc
2021-11-24 19:42:49 +05:30
Sviatoslav Sydorenko fa89944891
Add initial Sphinx docs 2021-11-18 01:36:13 +01:00
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 523021c9b5
Add `--auth-plugin` flag to override default basic auth plugin (#734)
* Allow override of `--auth-plugin`.

This can be used in scenarios where a hardcoded `--basic-auth`
credentials cannot be used across all your users.  May-be you
want to connect to a database before authorizing the request.
For all such scenario, disable in-build default auth plugin
by providing `--auth-plugin` flag.

* Allow usage of `--auth-plugin` flag without having to provide `--basic-auth` flag.  When `--basic-auth` flag is used, default auth plugin will load.  When `--basic-auth` and `--auth-plugin` flag is used, custom auth plugin will load

* Address test_main broken after auth_plugin flag

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

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

* Update README

* Fix long line

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-11-14 02:26:49 +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 fa18129f9b
`OP_NO_TLSv1_1` by default for upstream connection negotiations (#712)
* print mode via acceptor pool

* `OP_NO_TLSv1_1` by default for upstream connection negotiations. Fixes #639

* Proper fix for flaky static web server test.

Diff in payload was due to a different compression algorithm being used.

* mypy fixes
2021-11-09 03:10:16 +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 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 bf4ee90e21
CustomDnsResolver plugin, CloudflareDnsResolver plugin, Allow plugins to configure network interface (#671)
* Add CustomDnsResolver plugin.  Addresses #535 and #664

* Add cloudflare DNS resolver plugin

* Lint fixes
2021-11-05 07:36:02 +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 137ce457bb
Separate basic auth plugin outside of core server (#453)
* Separate basic auth plugin outside of core

* Put basic auth plugin at top
2020-10-14 20:00:29 +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 d6e60774ae
Add DEFAULT_MAX_SEND_SIZE and handle SSLWantWriteError errors when dispatching to upstream servers (#368) 2020-06-13 16:05:01 +05:30
Abhinav Singh ccaf868921
Response parser now reaches COMPLETE even when no body is expected (#220)
* Stash current changes

* Refactor into connection module

* Response parser state complete when no body expect

* Raise NotImplementedError if invalid state reached within parser
2019-12-02 19:18:43 -08:00