Secure.deduplicate_headers()

Deduplicate headers in headers_list according to the chosen policy.

Usage

Source

Secure.deduplicate_headers(
    *,
    action="raise",
    comma_join_ok=COMMA_JOIN_OK,
    multi_ok=MULTI_OK,
    logger=None
)

Parameters

action: DeduplicateAction = "raise"
Policy when encountering disallowed duplicates:
  • "raise": raise ValueError (default).
  • "first": keep the first instance and drop others.
  • "last": keep the last instance and drop others.
  • "concat": join values with commas when safe.
comma_join_ok: frozenset[str] = COMMA_JOIN_OK

Names (lowercased) for which RFC 7230-style comma joining is safe.

multi_ok: frozenset[str] = MULTI_OK

Names (lowercased) that are allowed to appear multiple times (for example Content-Security-Policy).

logger: logging.Logger | None = None
Optional logging.Logger used for warning messages when dropping duplicates in non-"raise" modes.

Returns

Secure
The same instance, for call chaining.

Raises

ValueError
If duplicates are found for headers that are not in multi_ok and the action is "raise" or "concat" for unsafe headers.