diff options
Diffstat (limited to 'components/script/dom/xmlhttprequest.rs')
-rw-r--r-- | components/script/dom/xmlhttprequest.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/components/script/dom/xmlhttprequest.rs b/components/script/dom/xmlhttprequest.rs index 10bc4cd8d57..e8025880f2e 100644 --- a/components/script/dom/xmlhttprequest.rs +++ b/components/script/dom/xmlhttprequest.rs @@ -121,6 +121,9 @@ pub struct XMLHttpRequest { response_xml: MutNullableHeap<JS<Document>>, #[ignore_heap_size_of = "Defined in hyper"] response_headers: DOMRefCell<Headers>, + override_mime_type: DOMRefCell<Option<Mime>>, + #[ignore_heap_size_of = "Defined in rust-encoding"] + override_charset: DOMRefCell<Option<EncodingRef>>, // Associated concepts request_method: DOMRefCell<Method>, @@ -158,6 +161,8 @@ impl XMLHttpRequest { response_type: Cell::new(_empty), response_xml: Default::default(), response_headers: DOMRefCell::new(Headers::new()), + override_mime_type: DOMRefCell::new(None), + override_charset: DOMRefCell::new(None), request_method: DOMRefCell::new(Method::Get), request_url: DOMRefCell::new(None), @@ -644,6 +649,21 @@ impl XMLHttpRequestMethods for XMLHttpRequest { ByteString::new(self.filter_response_headers().to_string().into_bytes()) } + // https://xhr.spec.whatwg.org/#the-overridemimetype()-method + fn OverrideMimeType(&self, mime: DOMString) -> ErrorResult { + match self.ready_state.get() { + XMLHttpRequestState::Loading | XMLHttpRequestState::Done => return Err(Error::InvalidState), + _ => {}, + } + let override_mime = try!(mime.parse::<Mime>().map_err(|_| Error::Syntax)); + *self.override_mime_type.borrow_mut() = Some(override_mime.clone()); + let value = override_mime.get_param(mime::Attr::Charset); + *self.override_charset.borrow_mut() = value.and_then(|value| { + encoding_from_whatwg_label(value) + }); + Ok(()) + } + // https://xhr.spec.whatwg.org/#the-responsetype-attribute fn ResponseType(&self) -> XMLHttpRequestResponseType { self.response_type.get() @@ -987,6 +1007,7 @@ impl XMLHttpRequest { } } + //FIXME: add support for override_mime_type and override_charset fn text_response(&self) -> String { let mut encoding = UTF_8 as EncodingRef; match self.response_headers.borrow().get() { |