فهرست منبع

support ipv6 (#850)

* support ipv6

There are many `:` in ipv6 address, uvicorn is support both v6 and v4, but `host, port = api.args.listen.split(":")` this line will fail to split v6 host

* [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>
TITC 1 سال پیش
والد
کامیت
7d74951dcd
1فایلهای تغییر یافته به همراه8 افزوده شده و 2 حذف شده
  1. 8 2
      tools/api_server.py

+ 8 - 2
tools/api_server.py

@@ -1,3 +1,4 @@
+import re
 from threading import Lock
 
 import pyrootutils
@@ -98,9 +99,14 @@ class API(ExceptionHandler):
 # Instead, it's better to use multiprocessing or independent models per thread.
 
 if __name__ == "__main__":
-
     api = API()
-    host, port = api.args.listen.split(":")
+
+    # IPv6 address format is [xxxx:xxxx::xxxx]:port
+    match = re.search(r"\[([^\]]+)\]:(\d+)$", api.args.listen)
+    if match:
+        host, port = match.groups()  # IPv6
+    else:
+        host, port = api.args.listen.split(":")  # IPv4
 
     uvicorn.run(
         api.app,