Add Option<&'static [u8]> method for header names
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.4k
- Forks
- 378
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 5
Description
Description
This enhancement focuses on improving the usability of the http crate when integrating Rust HTTP libraries with other VM engines, such as V8 (specifically for, but not limited to Deno). The goal is to provide embedding users with a specific method that allows extracting a static 7-bit string from a well-known ASCII header name. By treating header strings as interned strings in scripting engines [1] [2], we can effectively reduce garbage collection pressure, leading to enhanced performance and efficiency.
To achieve this, we propose introducing an Option<&'static [u8]> method for header names. This approach offers a more efficient means of passing header names across embedding boundaries. When working with static ASCII header names, this method allows direct access to the header name bytes across embedding boundaries, without the need for additional memory allocation or garbage collection overhead.
This may also be useful for Python embedders [2], as (I believe) the CPython engine allows creation of strings from const 1-byte buffers.
Alternatives
While we do have an as_bytes method on a header name, this does not tell us the provenance of those bytes, and whether the header is a StandardHeader. We cannot use these as "externally interned" strings in an embedding context because they may be allocated.
The hash function of the header could be used allow us to map between standard headers and interned strings in the embedded engine, but this requires an additional string comparison operation.
References
[1] V8's NewExternalOneByte method:
[2] Python's PyUnicode_FromKindAndData method (which I believe will avoid copies where necessary):
https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_FromKindAndData
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the header-name representation and its existing as_bytes method, then inspect how standard header names are identified. Add the proposed method so standard ASCII names can expose static bytes while other names return None, and add tests covering both cases. No specific files or test paths are mentioned in the issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100