script: dont unwrap in header set (#32973)

Signed-off-by: tobinio <tobias.frischmann1@gmail.com>
This commit is contained in:
ToBinio 2024-08-08 16:33:54 +02:00 committed by GitHub
parent b8cf0cf9af
commit 8fab6911d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 6 deletions

View file

@ -214,10 +214,20 @@ impl HeadersMethods for Headers {
}
// Step 7
// https://fetch.spec.whatwg.org/#concept-header-list-set
self.header_list.borrow_mut().insert(
HeaderName::from_str(&valid_name).unwrap(),
HeaderValue::from_bytes(&valid_value).unwrap(),
);
match HeaderValue::from_bytes(&valid_value) {
Ok(value) => {
self.header_list
.borrow_mut()
.insert(HeaderName::from_str(&valid_name).unwrap(), value);
},
Err(_) => {
// can't add the header, but we don't need to panic the browser over it
warn!(
"Servo thinks \"{:?}\" is a valid HTTP header value but HeaderValue doesn't.",
valid_value
);
},
};
Ok(())
}
}