2020-07-07 12:31:49 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
proxy.py
|
|
|
|
~~~~~~~~
|
|
|
|
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on
|
|
|
|
Network monitoring, controls & Application development, testing, debugging.
|
|
|
|
|
|
|
|
:copyright: (c) 2013-present by Abhinav Singh and contributors.
|
|
|
|
:license: BSD, see LICENSE for more details.
|
|
|
|
"""
|
|
|
|
import time
|
|
|
|
|
2020-07-09 16:01:29 +00:00
|
|
|
from proxy.core.acceptor import AcceptorPool
|
2020-07-07 12:31:49 +00:00
|
|
|
from proxy.common.flags import Flags
|
|
|
|
|
2020-07-09 16:01:29 +00:00
|
|
|
from examples.base_echo_server import BaseEchoServerHandler
|
2020-07-07 12:31:49 +00:00
|
|
|
|
|
|
|
|
2020-07-09 16:01:29 +00:00
|
|
|
class EchoServerHandler(BaseEchoServerHandler): # type: ignore
|
|
|
|
"""Sets client socket to non-blocking during initialization."""
|
2020-07-08 07:41:12 +00:00
|
|
|
|
2020-07-08 11:08:58 +00:00
|
|
|
def initialize(self) -> None:
|
|
|
|
self.client.connection.setblocking(False)
|
|
|
|
|
2020-07-07 12:31:49 +00:00
|
|
|
|
|
|
|
def main() -> None:
|
|
|
|
# This example requires `threadless=True`
|
|
|
|
pool = AcceptorPool(
|
2020-07-08 07:41:12 +00:00
|
|
|
flags=Flags(port=12345, num_workers=1, threadless=True),
|
2020-07-07 12:31:49 +00:00
|
|
|
work_klass=EchoServerHandler)
|
|
|
|
try:
|
|
|
|
pool.setup()
|
|
|
|
while True:
|
|
|
|
time.sleep(1)
|
|
|
|
finally:
|
|
|
|
pool.shutdown()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|