Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- stable
- beta
- nightly
- 1.39.0
- 1.46.0

include:
- rust: nightly
Expand Down
14 changes: 9 additions & 5 deletions src/header/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,16 @@ impl HeaderValue {
/// assert_eq!(val, "hello");
/// ```
#[inline]
pub fn from_static(src: &'static str) -> HeaderValue {
#[allow(unconditional_panic)] // required for the panic circumventon
#[track_caller]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we adding track_caller?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this will provide a more useful line number when the panic occurs. Instead of pointing at hyper's code, it will point at the user's HeaderValue::from_static line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does removing this attribute make the panic message much worse?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tried without and it doesn't seem to change anything. Removed!

pub const fn from_static(src: &'static str) -> HeaderValue {
let bytes = src.as_bytes();
for &b in bytes {
if !is_visible_ascii(b) {
panic!("invalid header value");
let mut i = 0;
while i < bytes.len() {
if !is_visible_ascii(bytes[i]) {
([] as [u8; 0])[0]; // Invalid header value
}
i += 1;
}

HeaderValue {
Expand Down Expand Up @@ -555,7 +559,7 @@ mod try_from_header_name_tests {
}
}

fn is_visible_ascii(b: u8) -> bool {
const fn is_visible_ascii(b: u8) -> bool {
b >= 32 && b < 127 || b == b'\t'
}

Expand Down