mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Fix return value of concept-header-list-get to Option<Vec<u8>>
This commit is contained in:
parent
d6d48510d9
commit
b6e4e44ccf
3 changed files with 26 additions and 26 deletions
|
@ -26,49 +26,53 @@ fn get_header_value_as_list(name: &str, headers: &HeaderMap) -> Option<Vec<Strin
|
||||||
return c != '\u{0022}' && c != '\u{002C}';
|
return c != '\u{0022}' && c != '\u{002C}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://fetch.spec.whatwg.org/#header-value-get-decode-and-split
|
||||||
// Step 1
|
// Step 1
|
||||||
let initial_value = get_value_from_header_list(name, headers);
|
let initial_value = get_value_from_header_list(name, headers);
|
||||||
|
|
||||||
if let Some(input) = initial_value {
|
if let Some(input) = initial_value {
|
||||||
// Step 4
|
// Step 1
|
||||||
let mut position = input.chars().peekable();
|
let input = input.into_iter().map(|u| char::from(u)).collect::<String>();
|
||||||
|
|
||||||
// Step 5
|
// Step 2
|
||||||
|
let mut position = s.chars().peekable();
|
||||||
|
|
||||||
|
// Step 3
|
||||||
let mut values: Vec<String> = vec![];
|
let mut values: Vec<String> = vec![];
|
||||||
|
|
||||||
// Step 6
|
// Step 4
|
||||||
let mut value = String::new();
|
let mut value = String::new();
|
||||||
|
|
||||||
// Step 7
|
// Step 5
|
||||||
while position.peek().is_some() {
|
while position.peek().is_some() {
|
||||||
// Step 7.1
|
// Step 5.1
|
||||||
value += &*collect_sequence(&mut position, char_is_not_quote_or_comma);
|
value += &*collect_sequence(&mut position, char_is_not_quote_or_comma);
|
||||||
|
|
||||||
// Step 7.2
|
// Step 5.2
|
||||||
if let Some(&ch) = position.peek() {
|
if let Some(&ch) = position.peek() {
|
||||||
if ch == '\u{0022}' {
|
if ch == '\u{0022}' {
|
||||||
// Step 7.2.1.1
|
// Step 5.2.1.1
|
||||||
value += &*collect_http_quoted_string(&mut position, false);
|
value += &*collect_http_quoted_string(&mut position, false);
|
||||||
|
|
||||||
// Step 7.2.1.2
|
// Step 5.2.1.2
|
||||||
if position.peek().is_some() {
|
if position.peek().is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// ch == '\u{002C}'
|
// ch == '\u{002C}'
|
||||||
|
|
||||||
// Step 7.2.2.2
|
// Step 5.2.2.2
|
||||||
position.next();
|
position.next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 7.3
|
// Step 5.3
|
||||||
value = value.trim_matches(HTTP_TAB_OR_SPACE).to_string();
|
value = value.trim_matches(HTTP_TAB_OR_SPACE).to_string();
|
||||||
|
|
||||||
// Step 7.4
|
// Step 5.4
|
||||||
values.push(value);
|
values.push(value);
|
||||||
|
|
||||||
// Step 7.5
|
// Step 5.5
|
||||||
value = String::new();
|
value = String::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,11 +5,8 @@
|
||||||
use headers::HeaderMap;
|
use headers::HeaderMap;
|
||||||
|
|
||||||
/// <https://fetch.spec.whatwg.org/#concept-header-list-get>
|
/// <https://fetch.spec.whatwg.org/#concept-header-list-get>
|
||||||
pub fn get_value_from_header_list(name: &str, headers: &HeaderMap) -> Option<String> {
|
pub fn get_value_from_header_list(name: &str, headers: &HeaderMap) -> Option<Vec<u8>> {
|
||||||
let values = headers
|
let values = headers.get_all(name).iter().map(|val| val.as_bytes());
|
||||||
.get_all(name)
|
|
||||||
.iter()
|
|
||||||
.map(|val| val.to_str().unwrap());
|
|
||||||
|
|
||||||
// Step 1
|
// Step 1
|
||||||
if values.size_hint() == (0, Some(0)) {
|
if values.size_hint() == (0, Some(0)) {
|
||||||
|
@ -17,5 +14,5 @@ pub fn get_value_from_header_list(name: &str, headers: &HeaderMap) -> Option<Str
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 2
|
// Step 2
|
||||||
return Some(values.collect::<Vec<&str>>().join(", "));
|
return Some(values.collect::<Vec<&[u8]>>().join(&[0x2C, 0x20][..]));
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,13 +85,12 @@ impl HeadersMethods for Headers {
|
||||||
|
|
||||||
// Step 3
|
// Step 3
|
||||||
if self.guard.get() == Guard::RequestNoCors {
|
if self.guard.get() == Guard::RequestNoCors {
|
||||||
let tmp_value = if let Some(value) =
|
let tmp_value = if let Some(mut value) =
|
||||||
get_value_from_header_list(&valid_name, &self.header_list.borrow())
|
get_value_from_header_list(&valid_name, &self.header_list.borrow())
|
||||||
{
|
{
|
||||||
let mut l = value.as_bytes().to_vec();
|
value.extend(b", ");
|
||||||
l.extend(b", ");
|
value.extend(valid_value.clone());
|
||||||
l.extend(valid_value.clone());
|
value
|
||||||
l
|
|
||||||
} else {
|
} else {
|
||||||
valid_value.clone()
|
valid_value.clone()
|
||||||
};
|
};
|
||||||
|
@ -158,7 +157,7 @@ impl HeadersMethods for Headers {
|
||||||
let valid_name = validate_name(name)?;
|
let valid_name = validate_name(name)?;
|
||||||
Ok(
|
Ok(
|
||||||
get_value_from_header_list(&valid_name, &self.header_list.borrow())
|
get_value_from_header_list(&valid_name, &self.header_list.borrow())
|
||||||
.map(|v| ByteString::new(v.as_bytes().to_vec())),
|
.map(|v| ByteString::new(v)),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,7 +301,7 @@ impl Headers {
|
||||||
header_vec.push((name.to_owned(), value.as_bytes().to_vec()));
|
header_vec.push((name.to_owned(), value.as_bytes().to_vec()));
|
||||||
}
|
}
|
||||||
} else if let Some(value) = get_value_from_header_list(name, &borrowed_header_list) {
|
} else if let Some(value) = get_value_from_header_list(name, &borrowed_header_list) {
|
||||||
header_vec.push((name.to_owned(), value.as_bytes().to_vec()));
|
header_vec.push((name.to_owned(), value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue