Skip to main content

DynamicContextProvider

Trait DynamicContextProvider 

Source
pub trait DynamicContextProvider:
    Send
    + Sync
    + Debug {
    // Required method
    fn provide_context(&self, info: &OperationInfo) -> HashMap<String, String>;
}
Expand description

Trait for providing dynamic request context.

Implementations can generate per-request context (e.g., authentication headers) based on the operation being performed. The provider is called synchronously before each namespace operation.

For RestNamespace, context keys that start with headers. are converted to HTTP headers by stripping the prefix. For example, {"headers.Authorization": "Bearer token"} becomes the Authorization: Bearer token header.

§Thread Safety

Implementations must be Send + Sync as the provider may be called from multiple threads concurrently.

§Error Handling

If the provider needs to signal an error, it should return an empty HashMap and log the error. The namespace operation will proceed without the additional context.

Required Methods§

Source

fn provide_context(&self, info: &OperationInfo) -> HashMap<String, String>

Provide context for a namespace operation.

§Arguments
  • info - Information about the operation being performed
§Returns

Returns a HashMap of context key-value pairs. For HTTP headers, use keys with the headers. prefix (e.g., headers.Authorization). Returns an empty HashMap if no additional context is needed.

Implementors§