Skip to content

Config API Spec ​

Overview ​

The Config module provides server configuration options. Configuration is set at the server level and can be shared across multiple server instances.

Interfaces ​

uvhttp_config_new ​

  • Signature: uvhttp_error_t uvhttp_config_new(uvhttp_config_t** config)
  • Purpose: Create a new config object with default values
  • Preconditions: config must be non-NULL.
  • Postconditions: On success, *config points to a config with all default values.
  • Error conditions:
    • UVHTTP_ERROR_INVALID_PARAM: config is NULL
    • UVHTTP_ERROR_OUT_OF_MEMORY: allocation failure
  • Thread safety: Not thread-safe.

uvhttp_config_free ​

  • Signature: void uvhttp_config_free(uvhttp_config_t* config)
  • Purpose: Free a config object
  • Preconditions: config can be NULL (no-op).
  • Postconditions: All memory is freed.
  • Thread safety: Not thread-safe.

uvhttp_config_set_defaults ​

  • Signature: void uvhttp_config_set_defaults(uvhttp_config_t* config)
  • Purpose: Reset config to default values
  • Preconditions: config must be valid.
  • Postconditions: All config fields are set to their default values.
  • Thread safety: Not thread-safe.

uvhttp_config_validate ​

  • Signature: int uvhttp_config_validate(const uvhttp_config_t* config)
  • Purpose: Validate config values against min/max bounds
  • Preconditions: config must be valid.
  • Returns: 0 if valid, non-zero (error code) if invalid.
  • Thread safety: Thread-safe for reads.

uvhttp_config_get_current / uvhttp_config_set_current ​

  • Signature: uvhttp_config_t* uvhttp_config_get_current(uvhttp_context_t* context) / void uvhttp_config_set_current(uvhttp_context_t* context, uvhttp_config_t* config)
  • Purpose: Get/set the current config on a context
  • Preconditions: context must be valid.
  • Thread safety: Not thread-safe.

Configurable Options ​

FieldTypeDefaultRangeDescription
max_connectionssize_t20481-65535Max concurrent connections
keepalive_timeoutint600-3600Keep-alive timeout (seconds)
request_timeoutint301-3600Request timeout (seconds)
max_header_sizesize_t8192256-65536Max header size (bytes)
max_body_sizesize_t104857601024-1073741824Max body size (bytes)
max_headersint648-256Max header count
read_buffer_sizesize_t4096256-65536Read buffer size (bytes)
backlogint1280-65535TCP listen backlog
tcp_nodelayint10-1TCP_NODELAY
tcp_keepaliveint10-1TCP keepalive
websocket_max_frame_sizesize_t655361024-1048576Max WebSocket frame (bytes)
websocket_ping_intervalint305-300Ping interval (seconds)
websocket_ping_timeoutint103-60Ping timeout (seconds)

Behavior Rules ​

  1. Defaults: All fields have sensible defaults. Callers can create a config and only change the fields they need.

  2. Validation: uvhttp_config_validate checks all fields against their valid ranges. Out-of-range values return UVHTTP_ERROR_INVALID_PARAM.

  3. Immutability: Config should not be modified while the server is listening. Changes take effect on the next listen.

Test Requirements ​

  • Config creation with defaults
  • Individual field modification
  • Validation of valid and invalid values
  • Boundary testing (min/max for each field)
  • NULL parameter handling
  • Config free (no-op on NULL)
  • Config set/get on context
  • Complete workflow (create, modify, validate, use, free)

Released under MIT License