asgi cgi handler
1.0.0
在 asgi 伺服器內執行 cgi 腳本
簡單的用法
import uvicorn
from asgi_cgi import HTTPCGIHandler , WebsocketCGIHandler
uvicorn . run ( HTTPCGIHandler ())
from fastapi import FastAPI
from asgi_cgi import HTTPCGIHandler , WebsocketCGIHandler , SSECGIHandler
app = FastAPI ( title = "CGI Server" )
app . mount ( "/cgi-bin" , HTTPCGIHandler ()) # type: ignore
app . mount ( "/ws" , WebsocketCGIHandler ()) # type: ignore
app . mount ( "/sse" , SSECGIHandler ()) # type: ignore
正如你所看到的,我們有 websocket 支持,這是受到 websocketd 的啟發。目前,還需要更多的測試。
WebsocketCGIHandler
將請求路由到端點可執行文件,並將 websocket 資料饋送到進程的 stdin 中,並將 stdout 逐行傳送到客戶端。
SSECGIHandler
,意思是server send event
,就像 websocket 一樣,但它只發送 stdout 到客戶端。
ErrHandler = Callable [[ bytes ], Union [ Awaitable [ None ], None ]]
class HTTPCGIHandler :
def __init__ ( self , directory : str = ..., error_handler : ErrHandler = ...) -> None : ...
class WebsocketCGIHandler :
def __init__ ( self , directory : str = ..., error_handler : ErrHandler = ...) -> None : ...
class SSECGIHandler :
def __init__ ( self , directory : str = ..., error_handler : ErrHandler = ...) -> None : ...