Documentation
¶
Overview ¶
Caddy plugin to serve Python apps.
Index ¶
- Variables
- type AppServer
- type Asgi
- type AsgiGlobalState
- type AsgiOperations
- type AsgiRequestHandler
- func (h *AsgiRequestHandler) CancelRequest()
- func (h *AsgiRequestHandler) CancelWebsocket(reason *C.char, code C.int)
- func (h *AsgiRequestHandler) Cleanup()
- func (h *AsgiRequestHandler) ConnectWebsocket(event *C.AsgiEvent)
- func (h *AsgiRequestHandler) DisconnectWebsocket(event *C.AsgiEvent)
- func (h *AsgiRequestHandler) HandleHeaders(statusCode C.int, headers *C.MapKeyVal, event *C.AsgiEvent)
- func (h *AsgiRequestHandler) HandleWebsocket(event *C.AsgiEvent) C.uint8_t
- func (h *AsgiRequestHandler) HandleWebsocketHeaders(statusCode C.int, headers *C.MapKeyVal, event *C.AsgiEvent)
- func (h *AsgiRequestHandler) ReadWebsocketMessage(event *C.AsgiEvent)
- func (h *AsgiRequestHandler) ReceiveStart(event *C.AsgiEvent) C.uint8_t
- func (h *AsgiRequestHandler) SendResponse(body *C.char, bodyLen C.size_t, moreBody C.uint8_t, event *C.AsgiEvent)
- func (h *AsgiRequestHandler) SendResponseWebsocket(body *C.char, bodyLen C.size_t, messageType C.uint8_t, event *C.AsgiEvent)
- func (h *AsgiRequestHandler) SetEvent(event *C.AsgiEvent)
- func (h *AsgiRequestHandler) SetWebsocketError(event *C.AsgiEvent, err error)
- func (h *AsgiRequestHandler) UpgradeWebsockets(headers http.Header, event *C.AsgiEvent)
- type CaddySnake
- func (CaddySnake) CaddyModule() caddy.ModuleInfo
- func (m *CaddySnake) Cleanup() error
- func (f *CaddySnake) Provision(ctx caddy.Context) error
- func (f CaddySnake) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
- func (f *CaddySnake) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
- func (m *CaddySnake) Validate() error
- type MapKeyVal
- type PythonMainThread
- type WebsocketState
- type Wsgi
- type WsgiGlobalState
- type WsgiResponse
Constants ¶
This section is empty.
Variables ¶
Functions ¶
This section is empty.
Types ¶
type AppServer ¶
type AppServer interface {
Cleanup() error
HandleRequest(w http.ResponseWriter, r *http.Request) error
}
AppServer defines the interface to interacting with a WSGI or ASGI server
type Asgi ¶
type Asgi struct {
// contains filtered or unexported fields
}
Asgi stores a reference to a Python Asgi application
func NewAsgi ¶
func NewAsgi(asgiPattern, workingDir, venvPath string, lifespan bool, logger *zap.Logger) (*Asgi, error)
NewAsgi imports a Python ASGI app
func (*Asgi) HandleRequest ¶
HandleRequest passes request down to Python ASGI app and writes responses and headers.
type AsgiGlobalState ¶
type AsgiGlobalState struct {
// contains filtered or unexported fields
}
func (*AsgiGlobalState) Cleanup ¶
func (s *AsgiGlobalState) Cleanup(requestID uint64)
func (*AsgiGlobalState) GetHandler ¶
func (s *AsgiGlobalState) GetHandler(requestID uint64) *AsgiRequestHandler
func (*AsgiGlobalState) Request ¶
func (s *AsgiGlobalState) Request(h *AsgiRequestHandler) uint64
type AsgiOperations ¶
type AsgiOperations struct {
// contains filtered or unexported fields
}
AsgiOperations stores operations that should be executed in the background
type AsgiRequestHandler ¶
type AsgiRequestHandler struct {
// contains filtered or unexported fields
}
AsgiRequestHandler stores pointers to the request and the response writer
func NewAsgiRequestHandler ¶
func NewAsgiRequestHandler(w http.ResponseWriter, r *http.Request, websocket bool) *AsgiRequestHandler
NewAsgiRequestHandler initializes handler and starts queue that consumes operations in the background.
func (*AsgiRequestHandler) CancelRequest ¶
func (h *AsgiRequestHandler) CancelRequest()
func (*AsgiRequestHandler) CancelWebsocket ¶
func (h *AsgiRequestHandler) CancelWebsocket(reason *C.char, code C.int)
func (*AsgiRequestHandler) Cleanup ¶
func (h *AsgiRequestHandler) Cleanup()
func (*AsgiRequestHandler) ConnectWebsocket ¶
func (h *AsgiRequestHandler) ConnectWebsocket(event *C.AsgiEvent)
func (*AsgiRequestHandler) DisconnectWebsocket ¶
func (h *AsgiRequestHandler) DisconnectWebsocket(event *C.AsgiEvent)
func (*AsgiRequestHandler) HandleHeaders ¶
func (*AsgiRequestHandler) HandleWebsocket ¶
func (h *AsgiRequestHandler) HandleWebsocket(event *C.AsgiEvent) C.uint8_t
func (*AsgiRequestHandler) HandleWebsocketHeaders ¶
func (*AsgiRequestHandler) ReadWebsocketMessage ¶
func (h *AsgiRequestHandler) ReadWebsocketMessage(event *C.AsgiEvent)
func (*AsgiRequestHandler) ReceiveStart ¶
func (h *AsgiRequestHandler) ReceiveStart(event *C.AsgiEvent) C.uint8_t
func (*AsgiRequestHandler) SendResponse ¶
func (*AsgiRequestHandler) SendResponseWebsocket ¶
func (*AsgiRequestHandler) SetEvent ¶
func (h *AsgiRequestHandler) SetEvent(event *C.AsgiEvent)
func (*AsgiRequestHandler) SetWebsocketError ¶
func (h *AsgiRequestHandler) SetWebsocketError(event *C.AsgiEvent, err error)
func (*AsgiRequestHandler) UpgradeWebsockets ¶
func (h *AsgiRequestHandler) UpgradeWebsockets(headers http.Header, event *C.AsgiEvent)
type CaddySnake ¶
type CaddySnake struct {
ModuleWsgi string `json:"module_wsgi,omitempty"`
ModuleAsgi string `json:"module_asgi,omitempty"`
Lifespan string `json:"lifespan,omitempty"`
WorkingDir string `json:"working_dir,omitempty"`
VenvPath string `json:"venv_path,omitempty"`
// contains filtered or unexported fields
}
CaddySnake module that communicates with a Python app
func (CaddySnake) CaddyModule ¶
func (CaddySnake) CaddyModule() caddy.ModuleInfo
CaddyModule returns the Caddy module information.
func (*CaddySnake) Cleanup ¶
func (m *CaddySnake) Cleanup() error
Cleanup frees resources uses by module
func (*CaddySnake) Provision ¶
func (f *CaddySnake) Provision(ctx caddy.Context) error
Provision sets up the module.
func (CaddySnake) ServeHTTP ¶
func (f CaddySnake) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error
ServeHTTP implements caddyhttp.MiddlewareHandler.
func (*CaddySnake) UnmarshalCaddyfile ¶
func (f *CaddySnake) UnmarshalCaddyfile(d *caddyfile.Dispenser) error
UnmarshalCaddyfile implements caddyfile.Unmarshaler.
func (*CaddySnake) Validate ¶
func (m *CaddySnake) Validate() error
Validate implements caddy.Validator.
type MapKeyVal ¶
type MapKeyVal struct {
// contains filtered or unexported fields
}
MapKeyVal wraps the same structure defined in the C layer
func NewMapKeyVal ¶
func NewMapKeyValFromSource ¶
type PythonMainThread ¶
type PythonMainThread struct {
// contains filtered or unexported fields
}
type WebsocketState ¶
type WebsocketState uint8
const ( WS_STARTING WebsocketState = iota + 2 WS_CONNECTED WS_DISCONNECTED )
type Wsgi ¶
type Wsgi struct {
// contains filtered or unexported fields
}
Wsgi stores a reference to a Python Wsgi application
func (*Wsgi) HandleRequest ¶
HandleRequest passes request down to Python Wsgi app and writes responses and headers.
type WsgiGlobalState ¶
WsgiGlobalState holds the global state for all requests to WSGI apps
func (*WsgiGlobalState) Request ¶
func (s *WsgiGlobalState) Request() int64
Request creates a new request handler and returns its ID
func (*WsgiGlobalState) Response ¶
func (s *WsgiGlobalState) Response(requestID int64, response WsgiResponse)
Response sends the response to the channel and closes it
func (*WsgiGlobalState) WaitResponse ¶
func (s *WsgiGlobalState) WaitResponse(requestID int64) WsgiResponse
WaitResponse waits for the response from the channel and returns it
type WsgiResponse ¶
type WsgiResponse struct {
// contains filtered or unexported fields
}
WsgiResponse holds the response from the WSGI app
func (*WsgiResponse) Write ¶
func (r *WsgiResponse) Write(w http.ResponseWriter)
