Update mypy (#449)
This commit is contained in:
parent
b5ff5c924f
commit
4804c534f8
|
@ -12,6 +12,7 @@ Table of Contents
|
|||
* [SSL Echo Server](#ssl-echo-server)
|
||||
* [SSL Echo Client](#ssl-echo-client)
|
||||
* [PubSub Eventing](#pubsub-eventing)
|
||||
* [Connect Tunnel](#connect-tunnel)
|
||||
|
||||
## WebSocket Client
|
||||
|
||||
|
@ -115,3 +116,23 @@ bye!!!
|
|||
DEBUG:proxy.core.event.subscriber:Un-subscribed relay sub id 5eb22010764f4d44900f41e2fb408ca6 from core events
|
||||
Received 52724 events from main thread, 60172 events from another process, in 21.50117802619934 seconds
|
||||
```
|
||||
|
||||
## Connect Tunnel
|
||||
|
||||
A simple HTTP proxy server supporting only CONNECT (https) requests.
|
||||
|
||||
1. Uses `HttpParser` for request parsing.
|
||||
2. Uses `TcpServerConnection` to establish upstream connection.
|
||||
3. Overrides `BaseServer` methods to also register read/write events for upstream connection.
|
||||
|
||||
Start `connect_tunnel.py` as:
|
||||
|
||||
```
|
||||
❯ PYTHONPATH=. python examples/connect_tunnel.py
|
||||
```
|
||||
|
||||
Send https requests via tunnel as:
|
||||
|
||||
```
|
||||
❯ curl -x localhost:12345 https://httpbin.org/get
|
||||
```
|
||||
|
|
|
@ -66,12 +66,7 @@ class ConnectTunnelHandler(BaseServerHandler): # type: ignore
|
|||
assert self.request.state == httpParserStates.COMPLETE
|
||||
|
||||
# Establish connection with upstream
|
||||
assert self.request.host and self.request.port
|
||||
self.upstream = TcpServerConnection(
|
||||
text_(self.request.host), self.request.port)
|
||||
self.upstream.connect()
|
||||
print('Connection established with upstream {0}:{1}'.format(
|
||||
text_(self.request.host), self.request.port))
|
||||
self.connect_upstream()
|
||||
|
||||
# Queue tunnel established response to client
|
||||
self.client.queue(
|
||||
|
@ -113,6 +108,14 @@ class ConnectTunnelHandler(BaseServerHandler): # type: ignore
|
|||
self.upstream.flush()
|
||||
return False
|
||||
|
||||
def connect_upstream(self) -> None:
|
||||
assert self.request.host and self.request.port
|
||||
self.upstream = TcpServerConnection(
|
||||
text_(self.request.host), self.request.port)
|
||||
self.upstream.connect()
|
||||
print('Connection established with upstream {0}:{1}'.format(
|
||||
text_(self.request.host), self.request.port))
|
||||
|
||||
|
||||
def main() -> None:
|
||||
# This example requires `threadless=True`
|
||||
|
|
|
@ -211,8 +211,7 @@ class socket_connection(contextlib.ContextDecorator):
|
|||
if self.conn:
|
||||
self.conn.close()
|
||||
|
||||
def __call__(self, func: Callable[..., Any]
|
||||
) -> Callable[[Tuple[Any, ...], Dict[str, Any]], Any]:
|
||||
def __call__(self, func: Callable[..., Any]) -> Callable[[Tuple[Any, ...], Dict[str, Any]], Any]: # type: ignore
|
||||
@functools.wraps(func)
|
||||
def decorated(*args: Any, **kwargs: Any) -> Any:
|
||||
with self as conn:
|
||||
|
|
|
@ -4,7 +4,7 @@ flake8==3.8.4
|
|||
pytest==6.1.1
|
||||
pytest-cov==2.10.1
|
||||
autopep8==1.5.4
|
||||
mypy==0.782
|
||||
mypy==0.790
|
||||
py-spy==0.3.3
|
||||
codecov==2.1.10
|
||||
tox==3.20.1
|
||||
|
|
Loading…
Reference in New Issue