Skip to content

fix: accept case-insensitive byte range units - #13

Merged
bancek merged 1 commit into
bancek:masterfrom
robjtede:fix/case-insensitive-range-units
Oct 19, 2026
Merged

bancek merged 1 commit into
bancek:masterfrom
robjtede:fix/case-insensitive-range-units

Conversation

@robjtede

Copy link
Copy Markdown
Contributor

Accept case-insensitive byte range units in HttpRange::parse and parse_bytes, as required by RFC 9110 §14.1.

Use an ASCII case-insensitive prefix comparison without allocation, and add mixed-case inputs to the existing parser tests.

Fixes #12.

@robjtede
robjtede force-pushed the fix/case-insensitive-range-units branch from 222bd42 to 52d0d1e Compare October 19, 2026 11:37
@bancek

bancek commented Oct 19, 2026

Copy link
Copy Markdown
Owner

I did some benchmarking a custom unrolled check is faster:

fn has_bytes_unit(header: &[u8]) -> bool {
    if header.len() < PREFIX_LEN {
        return false;
    }

    let unit = &header[..PREFIX_LEN];
    ((unit[0] | 0x20) == b'b')
        & ((unit[1] | 0x20) == b'y')
        & ((unit[2] | 0x20) == b't')
        & ((unit[3] | 0x20) == b'e')
        & ((unit[4] | 0x20) == b's')
        & (unit[5] == b'=')
}
Implementation Prefix check
starts_with (old behavior, lowercase input) 2.34 ns
eq_ignore_ascii_case (get/slice/first_chunk, all equal) 5.38 ns
manual | 0x20, branchless 2.37 ns
manual | 0x20, short-circuit && 2.94 ns
masked u32 + u16 2.35 ns
to_ascii_lowercase allocation 18.93 ns

@robjtede
robjtede force-pushed the fix/case-insensitive-range-units branch from 52d0d1e to b71278c Compare October 19, 2026 12:13
@bancek
bancek merged commit bf0e301 into bancek:master Oct 19, 2026
1 check passed
@robjtede
robjtede deleted the fix/case-insensitive-range-units branch October 19, 2026 12:36
@bancek

bancek commented Oct 19, 2026

Copy link
Copy Markdown
Owner

I released v0.1.6

https://crates.io/crates/http-range/0.1.6

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.

Accept case-insensitive range units

2 participants