Skip to content

Improve headers ergonomics - #705

Merged
RobertoPrevato merged 3 commits into
mainfrom
feat/headers-ux
Oct 12, 2026
Merged

RobertoPrevato merged 3 commits into
mainfrom
feat/headers-ux

Conversation

@RobertoPrevato

Copy link
Copy Markdown
Member
  • Improve header ergonomics: dictionary-style assignment and Headers.update()
    accept strings or bytes, so response.headers["X-Example"] = "value" is
    supported while headers remain stored internally as bytes. String names use
    ASCII and string values use Latin-1; unrepresentable characters raise
    UnicodeEncodeError. Assignment still replaces all case-insensitive matches.
  • Add Headers.get_text_values(name, encoding="latin-1") to decode matching
    values on demand as a tuple, preserving repeated header entries.
    get_first_text() returns the first value as a string, or None when absent;
    get_single_text() returns a string and requires exactly one matching entry,
    raising ValueError otherwise. Both also accept an explicit encoding.
    Existing byte-valued reads and low-level byte-based methods remain unchanged.
  • Complete header dictionary symmetry: lookup, membership, and deletion accept
    string or byte names; lookup always returns byte values. Add Headers.add_text()
    to append without replacing matches, and Headers.from_values() to build a
    byte-backed collection from mappings or iterables while preserving duplicates.
  • Use the same ASCII-name/Latin-1-value policy for HTTP client headers= and
    default_headers=, route header filters, and testing-client iterable headers.
    Previously, HTTP client string values required ASCII. Testing-client dictionaries
    retain their historical UTF-8 encoding for backward compatibility.
    Pass explicitly encoded bytes for field-specific encodings.
  • Preserve raw header values when sending HTTP/2 requests, without decoding them
    as UTF-8, so Latin-1 values and explicitly encoded bytes reach the wire unchanged.

@RobertoPrevato RobertoPrevato changed the title Improve headers ux Improve headers ergonomics Oct 12, 2026
@RobertoPrevato
RobertoPrevato merged commit 4c13952 into main Oct 12, 2026
31 of 32 checks passed
@RobertoPrevato
RobertoPrevato deleted the feat/headers-ux branch October 12, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant