Skip to content

HTTP runtime configuration

hololinked.server.http.config.RuntimeConfig

Bases: BaseModel

Runtime configuration for HTTP server and handlers.

Pass the attributes of this class as a dictionary to the config argument of HTTPServer.

Source code in repo/hololinked/hololinked/server/http/config.py
class RuntimeConfig(BaseModel):
    """
    Runtime configuration for HTTP server and handlers.

    Pass the attributes of this class as a dictionary to the `config` argument of `HTTPServer`.
    """

    cors: bool = False
    """use `True` to set CORS headers for the HTTP server, this is useful for local networks"""

    property_handler: type[RPCHandler] | Any = PropertyHandler
    """handler class to be used for property interactions"""
    action_handler: type[RPCHandler] | Any = ActionHandler
    """handler class to be used for action interactions"""
    event_handler: type[EventHandler] | Any = EventHandler
    """handler class to be used for event interactions"""
    RW_multiple_properties_handler: type[RPCHandler] | Any = RWMultiplePropertiesHandler
    """handler class to be used for read/write multiple properties interactions"""
    thing_description_handler: type[ThingDescriptionHandler] | Any = ThingDescriptionHandler
    """handler class to be used for thing description"""
    liveness_probe_handler: type[LivenessProbeHandler] | Any = LivenessProbeHandler
    """handler class to be used for liveness probe"""
    readiness_probe_handler: type[ReadinessProbeHandler] | Any = ReadinessProbeHandler
    """handler class to be used for readiness probe"""
    stop_handler: type[StopHandler] | Any = StopHandler
    """handler class to be used for stopping server"""

    thing_description_service: type[ThingDescriptionService] | Any = ThingDescriptionService
    """service class to be used for generating thing description"""

    server_id: str = ""
    """identity of the server."""

    allowed_clients: list[str] | None = Field(default=None)
    """
    Serves request and sets CORS only from these clients, other clients are rejected with 401. 
    Unlike pure CORS, the server resource is not even executed if the client is not 
    an allowed client. if None, any client is served. Not inherently a safety feature in public networks, 
    and more useful in private networks when the remote origin is known reliably.
    """

    security_schemes: list[Security] | None = Field(default=None)
    """
    List of security schemes to be used by the server, 
    it is sufficient that one scheme passes for a request to be authorized.
    Combo security schemes are not yet supported (but will be in future).
    """

Attributes

cors class-attribute instance-attribute

cors: bool = False

use True to set CORS headers for the HTTP server, this is useful for local networks

allowed_clients class-attribute instance-attribute

allowed_clients: list[str] | None = Field(default=None)

Serves request and sets CORS only from these clients, other clients are rejected with 401. Unlike pure CORS, the server resource is not even executed if the client is not an allowed client. if None, any client is served. Not inherently a safety feature in public networks, and more useful in private networks when the remote origin is known reliably.

security_schemes class-attribute instance-attribute

security_schemes: list[Security] | None = Field(default=None)

List of security schemes to be used by the server, it is sufficient that one scheme passes for a request to be authorized. Combo security schemes are not yet supported (but will be in future).

server_id class-attribute instance-attribute

server_id: str = ''

identity of the server.

property_handler class-attribute instance-attribute

property_handler: type[RPCHandler] | Any = PropertyHandler

handler class to be used for property interactions

action_handler class-attribute instance-attribute

action_handler: type[RPCHandler] | Any = ActionHandler

handler class to be used for action interactions

event_handler class-attribute instance-attribute

event_handler: type[EventHandler] | Any = EventHandler

handler class to be used for event interactions

RW_multiple_properties_handler class-attribute instance-attribute

RW_multiple_properties_handler: type[RPCHandler] | Any = RWMultiplePropertiesHandler

handler class to be used for read/write multiple properties interactions

thing_description_handler class-attribute instance-attribute

thing_description_handler: type[ThingDescriptionHandler] | Any = ThingDescriptionHandler

handler class to be used for thing description

liveness_probe_handler class-attribute instance-attribute

liveness_probe_handler: type[LivenessProbeHandler] | Any = LivenessProbeHandler

handler class to be used for liveness probe

readiness_probe_handler class-attribute instance-attribute

readiness_probe_handler: type[ReadinessProbeHandler] | Any = ReadinessProbeHandler

handler class to be used for readiness probe

stop_handler class-attribute instance-attribute

stop_handler: type[StopHandler] | Any = StopHandler

handler class to be used for stopping server

thing_description_service class-attribute instance-attribute

thing_description_service: type[ThingDescriptionService] | Any = ThingDescriptionService

service class to be used for generating thing description

Pass these as a plain dictionary to the config argument of HTTPServer — not as a RuntimeConfig instance:

HTTPServer(config=dict(cors=True, property_handler=MyPropertyHandler))

hololinked.server.http.config.HandlerMetadata

Bases: BaseModel

Specific metadata when a request handler has been initialized, in other words, handler specific metadata.

Source code in repo/hololinked/hololinked/server/http/config.py
class HandlerMetadata(BaseModel):
    """Specific metadata when a request handler has been initialized, in other words, handler specific metadata."""

    http_methods: tuple[str, ...] = tuple()
    """HTTP methods supported by the handler"""

Attributes

http_methods class-attribute instance-attribute

http_methods: tuple[str, ...] = tuple()

HTTP methods supported by the handler