class documentation

class HttpServer(object):

View In Hierarchy

The HTTP server for the CSE.

Method addEndpoint Add an endpoint to the Flask application.
Method configure Configure the HTTP server with the given configuration.
Method getEndpoints Get all registered HTTP endpoints.
Method handleAuthentication Handle the authentication for the current request.
Method handleDELETE Handle a DELETE request.
Method handleGET Handle a GET request.
Method handlePATCH Support PATCH instead of DELETE for http/1.0.
Method handlePOST Handle a POST request.
Method handlePUT Handle a PUT request.
Method init Start the HTTP server. This sets up the Flask application, configures CORS, adds endpoints, and initializes the web UI.
Method pause Stop handling requests.
Method run Run the http server in a separate thread.
Method sendHttpRequest Send an http request.
Method shutdown Shutting down the http server.
Method unpause Continue handling requests.
Method validate Validate the configuration for the HTTP server.
Class Variable __slots__ The slots for the HttpServer class to optimize memory usage.
Class Variable cseShutdown Injected function to shut down the CSE.
Class Variable operation2method A mapping of operations to the corresponding HTTP methods.
Class Variable requestManager Injected RequestManager instance.
Class Variable security Injected SecurityManager instance.
Instance Variable backgroundActor The background worker for the HTTP server.
Instance Variable flaskApp The Flask application instance.
Instance Variable httpActor The background worker for the HTTP server.
Instance Variable isStopped Whether the HTTP server is stopped.
Instance Variable serverID The server's ID for HTTP response headers.
Method _dissectHttpRequest Dissect an HTTP request. Combine headers and contents into a single structure. Result is returned in Result.request.
Method _handleRequest Get and check all the necessary information from the request and build the internal strutures. Then, depending on the operation, call the associated request handler.
Method _hasContentType Check if the request has a content type that is supported by the CSE. This is used to determine if the request can be processed.
Method _prepareResponse Prepare the response for a request. If request is given then set it for the response.
Method _run Run the http server. This method is run in a separate thread. It starts the Flask application and serves it.
Class Variable _hdrArgument Regex to check if the request has a content type that is supported by the CSE.
Instance Variable _responseHeaders Additional headers for HTTP responses.
def addEndpoint(self, endpoint: str | None = None, endpoint_name: str | None = None, handler: FlaskHandler | None = None, methods: list[str] | None = None, strictSlashes: bool | None = True) -> str:

Add an endpoint to the Flask application.

Parameters
endpoint:str | NoneThe endpoint URL.
endpoint_name:str | NoneThe name of the endpoint.
handler:FlaskHandler | NoneThe handler function for the endpoint.
methods:list[str] | NoneThe HTTP methods allowed for this endpoint.
strictSlashes:bool | NoneWhether to enforce strict slashes in the URL.
Returns
strThe path of the registered endpoint.
def configure(self, config: Configuration):

Configure the HTTP server with the given configuration.

Parameters
config:ConfigurationThe configuration to use for the HTTP server.
def getEndpoints(self) -> list[dict]:

Get all registered HTTP endpoints.

Returns
list[dict]List of dictionaries containing endpoint information.
def handleAuthentication(self) -> AuthorizationResult:

Handle the authentication for the current request.

Returns
AuthorizationResultEnum value for the authentication result.
def handleDELETE(self, path: str | None = None) -> Response:

Handle a DELETE request.

Parameters
path:str | NoneThe path of the request.
Returns
ResponseUndocumented
def handleGET(self, path: str | None = None) -> Response:

Handle a GET request.

Parameters
path:str | NoneThe path of the request.
Returns
ResponseUndocumented
def handlePATCH(self, path: str | None = None) -> Response:

Support PATCH instead of DELETE for http/1.0.

Parameters
path:str | NoneThe path of the request.
Returns
ResponseUndocumented
def handlePOST(self, path: str | None = None) -> Response:

Handle a POST request.

Parameters
path:str | NoneThe path of the request.
Returns
ResponseUndocumented
def handlePUT(self, path: str | None = None) -> Response:

Handle a PUT request.

Parameters
path:str | NoneThe path of the request.
Returns
ResponseUndocumented
def init(self):

Start the HTTP server. This sets up the Flask application, configures CORS, adds endpoints, and initializes the web UI.

def pause(self):

Stop handling requests.

def run(self):

Run the http server in a separate thread.

def sendHttpRequest(self, request: CSERequest, url: str, ignoreResponse: bool) -> Result:

Send an http request.

The result is always returned in Result.data, even an error/dbg message.

def shutdown(self):

Shutting down the http server.

def unpause(self):

Continue handling requests.

def validate(self, config: Configuration):

Validate the configuration for the HTTP server.

Parameters
config:ConfigurationThe configuration to validate.
__slots__: tuple[str, ...] =

The slots for the HttpServer class to optimize memory usage.

cseShutdown: Callable[[], None] =

Injected function to shut down the CSE.

operation2method =

A mapping of operations to the corresponding HTTP methods.

requestManager: RequestManager =

Injected RequestManager instance.

security: SecurityManager =

Injected SecurityManager instance.

backgroundActor: BackgroundWorker =

The background worker for the HTTP server.

flaskApp =

The Flask application instance.

httpActor: BackgroundWorker | None =

The background worker for the HTTP server.

isStopped: bool =

Whether the HTTP server is stopped.

serverID =

The server's ID for HTTP response headers.

def _dissectHttpRequest(self, request: Request, operation: Operation, path: str) -> Result:

Dissect an HTTP request. Combine headers and contents into a single structure. Result is returned in Result.request.

def _handleRequest(self, path: str, operation: Operation, authResult: AuthorizationResult) -> Response:

Get and check all the necessary information from the request and build the internal strutures. Then, depending on the operation, call the associated request handler.

def _hasContentType(self) -> bool:

Check if the request has a content type that is supported by the CSE. This is used to determine if the request can be processed.

Returns
boolTrue if the request has a content type that is supported, False otherwise.
def _prepareResponse(self, result: Result, originalRequest: CSERequest | None = None) -> Response:

Prepare the response for a request. If request is given then set it for the response.

def _run(self):

Run the http server. This method is run in a separate thread. It starts the Flask application and serves it.

_hdrArgument =

Regex to check if the request has a content type that is supported by the CSE.

_responseHeaders =

Additional headers for HTTP responses.