asgi cgi handler
1.0.0
run cgi scripts inside an asgi server
simple usage
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
As you can see, we have websocket support, which is inspired by websocketd. Currently, more tests are needed.
The WebsocketCGIHandler
route requests to endpoint executables and feed websocket data
into process's stdin and send stdout to client line by line.
The SSECGIHandler
, means server send event
, is just like the websocket one, but it only send stdout to client.
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: ...