Auto merge of #10272 - creativcoder:implement-data-url-fetch, r=jdm

implements data-url fetching

Fixes #10165
jdm mentioned of decoupling the, payload loading mechanism to data_loader.rs. So accordingly a `decoder` method has been added to data_loader.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/10272)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-04-01 15:12:30 +05:30
commit 9f892edd87
3 changed files with 85 additions and 23 deletions

View file

@ -2,6 +2,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use data_loader::decode;
use fetch::cors_cache::{BasicCORSCache, CORSCache, CacheRequestDetails};
use http_loader::{NetworkHttpRequestFactory, create_http_connector, obtain_response};
use hyper::header::{Accept, CacheControl, IfMatch, IfRange, IfUnmodifiedSince, Location};
@ -305,7 +306,23 @@ fn basic_fetch(request: Rc<Request>) -> Response {
http_fetch(request.clone(), BasicCORSCache::new(), false, false, false)
},
"blob" | "data" | "file" | "ftp" => {
"data" => {
if *request.method.borrow() == Method::Get {
match decode(&url) {
Ok((mime, bytes)) => {
let mut response = Response::new();
*response.body.lock().unwrap() = ResponseBody::Done(bytes);
response.headers.set(ContentType(mime));
response
},
Err(_) => Response::network_error()
}
} else {
Response::network_error()
}
},
"blob" | "file" | "ftp" => {
// XXXManishearth handle these
panic!("Unimplemented scheme for Fetch")
},