1
1
"""MultiHost capable aiohttp Site."""
2
2
from __future__ import annotations
3
3
4
+ import asyncio
4
5
from ssl import SSLContext
5
6
6
7
from aiohttp import web
7
8
from yarl import URL
8
9
9
10
10
- class MultiHostTCPSite (web .TCPSite ):
11
+ class MultiHostTCPSite (web .BaseSite ):
11
12
"""MultiHost capable aiohttp Site.
12
13
13
14
Vanilla TCPSite accepts only str as host. However, the underlying asyncio's
@@ -16,6 +17,8 @@ class MultiHostTCPSite(web.TCPSite):
16
17
explicitly), we would like to pass an array of strings.
17
18
"""
18
19
20
+ __slots__ = ("_host" , "_port" , "_reuse_address" , "_reuse_port" , "_hosturl" )
21
+
19
22
def __init__ (
20
23
self ,
21
24
runner : web .BaseRunner ,
@@ -44,3 +47,19 @@ def name(self) -> str:
44
47
scheme = "https" if self ._ssl_context else "http"
45
48
host = self ._host [0 ] if isinstance (self ._host , list ) else "0.0.0.0"
46
49
return str (URL .build (scheme = scheme , host = host , port = self ._port ))
50
+
51
+ async def start (self ) -> None :
52
+ """Start server."""
53
+ await super ().start ()
54
+ loop = asyncio .get_running_loop ()
55
+ server = self ._runner .server
56
+ assert server is not None
57
+ self ._server = await loop .create_server (
58
+ server ,
59
+ self ._host ,
60
+ self ._port ,
61
+ ssl = self ._ssl_context ,
62
+ backlog = self ._backlog ,
63
+ reuse_address = self ._reuse_address ,
64
+ reuse_port = self ._reuse_port ,
65
+ )
0 commit comments