Skip to content

Commit

Permalink
makes XMLHttpRequest::SetRequestHeader call dom::headers::is_forbidde…
Browse files Browse the repository at this point in the history
…n_header_name
  • Loading branch information
malisas committed Jul 19, 2016
1 parent 530b027 commit 60549c4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 16 deletions.
2 changes: 1 addition & 1 deletion components/script/dom/headers.rs
Expand Up @@ -102,7 +102,7 @@ fn is_forbidden_response_header(name: &str) -> bool {
}

// https://fetch.spec.whatwg.org/#forbidden-header-name
fn is_forbidden_header_name(name: &str) -> bool {
pub fn is_forbidden_header_name(name: &str) -> bool {
let disallowed_headers =
["accept-charset", "accept-encoding",
"access-control-request-headers",
Expand Down
18 changes: 3 additions & 15 deletions components/script/dom/xmlhttprequest.rs
Expand Up @@ -25,6 +25,7 @@ use dom::document::DocumentSource;
use dom::document::{Document, IsHTMLDocument};
use dom::event::{Event, EventBubbles, EventCancelable};
use dom::eventtarget::EventTarget;
use dom::headers::is_forbidden_header_name;
use dom::progressevent::ProgressEvent;
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
use dom::xmlhttprequestupload::XMLHttpRequestUpload;
Expand Down Expand Up @@ -416,21 +417,8 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
// Step 5
// Disallowed headers and header prefixes:
// https://fetch.spec.whatwg.org/#forbidden-header-name
let disallowedHeaders =
["accept-charset", "accept-encoding",
"access-control-request-headers",
"access-control-request-method",
"connection", "content-length",
"cookie", "cookie2", "date", "dnt",
"expect", "host", "keep-alive", "origin",
"referer", "te", "trailer", "transfer-encoding",
"upgrade", "via"];

let disallowedHeaderPrefixes = ["sec-", "proxy-"];

if disallowedHeaders.iter().any(|header| *header == s) ||
disallowedHeaderPrefixes.iter().any(|prefix| s.starts_with(prefix)) {
return Ok(())
if is_forbidden_header_name(s) {
return Ok(());
} else {
s
}
Expand Down

0 comments on commit 60549c4

Please sign in to comment.