Skip to content

Headers#3123

Closed
ademmenh wants to merge 5 commits intoKludex:mainfrom
ademmenh:headers
Closed

Headers#3123
ademmenh wants to merge 5 commits intoKludex:mainfrom
ademmenh:headers

Conversation

@ademmenh
Copy link

@ademmenh ademmenh commented Feb 1, 2026

Pull Request: Optimize Header Handling for Server Push

Description

This pull request introduces a new get_raw_list method to the Headers datastructure and leverages it to optimize the send_push_promise function in the Request class.

The primary goal is to reduce unnecessary decoding and encoding overhead when dealing with raw header bytes during server push operations.

Changes

Core Changes

  • starlette/datastructures.py:

    • Added Headers.get_raw_list(key: str) -> list[bytes]: Retrieves the raw byte values for a given header key.
  • starlette/requests.py:

    • Refactored send_push_promise (internal logic within Request) to use get_raw_list.
    • Improved performance by encoding header names once and avoiding the redundant decode("latin-1") -> encode("latin-1") cycle for header values.

Tests

  • tests/test_datastructures.py:
    • Added test case to verify that get_raw_list correctly returns byte values for multi-value headers.

@Kludex
Copy link
Owner

Kludex commented Feb 14, 2026

Thanks for the contribution, @ademmenh !

I'm going to close this one — HTTP/2 Server Push has been removed from all major browsers, so send_push_promise is effectively dead code. Optimizing it and expanding the Headers API surface for it isn't worth the trade-off.

@Kludex Kludex closed this Feb 14, 2026
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.

2 participants