Update mypy (#449)

This commit is contained in:
Abhinav Singh 2020-10-10 16:23:29 +05:30 committed by GitHub
parent b5ff5c924f
commit 4804c534f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 9 deletions

View File

@ -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
```

View File

@ -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`

View File

@ -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:

View File

@ -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