Skip to main content

Module client

Module client 

Source
Expand description

§modo::client

Client-context types and helpers shared across HTTP, audit, and session code paths.

Provides:

  • ClientInfo — structured client metadata (IP, user-agent, parsed device fields, server-computed fingerprint). Populated automatically in handlers via FromRequestParts, or built manually for non-HTTP contexts (background jobs, CLI tools).
  • parse_device_name / parse_device_typeUser-Agent classifiers.
  • compute_fingerprint — SHA-256 hash of UA + Accept-Language + Accept-Encoding for session-hijack detection.
  • header_str — small helper that reads a header as &str, returning "" when absent or non-UTF-8. Useful for code paths that already hold a &HeaderMap and need the same defaulting ClientInfo uses internally.

Used by crate::audit (persisted with audit events) and crate::auth::session (session creation, fingerprint validation).

§Quick start

use modo::client::ClientInfo;

async fn handler(info: ClientInfo) -> String {
    format!(
        "{} from {}",
        info.device_name_value().unwrap_or("Unknown"),
        info.ip_value().unwrap_or("?"),
    )
}

Structs§

ClientInfo
Client request context: IP, user-agent, parsed device fields, and a server-computed browser fingerprint.

Functions§

compute_fingerprint
Compute a SHA-256 fingerprint from three request headers.
header_str
Extract a header value as a string slice, returning "" when absent or non-UTF-8.
parse_device_name
Derive a human-readable device name from the User-Agent string.
parse_device_type
Classify the device type from the User-Agent string.