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