diff options
author | Rahul Sharma <rsconceptx@gmail.com> | 2016-03-29 21:54:19 +0530 |
---|---|---|
committer | Rahul Sharma <rsconceptx@gmail.com> | 2016-04-01 09:49:08 +0530 |
commit | 3e74164e5f79a2eb177f778c7f8bedb72514673f (patch) | |
tree | 4dea6aa8e51233e02a565b142c1dcc12fa05e7b3 /components/net/fetch/methods.rs | |
parent | 9a8d62286c6556fca7471f2db37f896174bc4d9e (diff) | |
download | servo-3e74164e5f79a2eb177f778c7f8bedb72514673f.tar.gz servo-3e74164e5f79a2eb177f778c7f8bedb72514673f.zip |
implements data-url fetching
Diffstat (limited to 'components/net/fetch/methods.rs')
-rw-r--r-- | components/net/fetch/methods.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/components/net/fetch/methods.rs b/components/net/fetch/methods.rs index 976b1e0b5ee..7c1cb5e3416 100644 --- a/components/net/fetch/methods.rs +++ b/components/net/fetch/methods.rs @@ -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") }, |