mirror of
https://github.com/servo/servo.git
synced 2025-06-06 00:25:37 +00:00
Redirect to an error page when file's not found
This commit is contained in:
parent
3eef814c4d
commit
b17ca9bdc1
4 changed files with 24 additions and 5 deletions
|
@ -19,7 +19,9 @@ pub fn factory(mut load_data: LoadData,
|
||||||
start_chan: LoadConsumer,
|
start_chan: LoadConsumer,
|
||||||
classifier: Arc<MIMEClassifier>,
|
classifier: Arc<MIMEClassifier>,
|
||||||
cancel_listener: CancellationListener) {
|
cancel_listener: CancellationListener) {
|
||||||
match load_data.url.non_relative_scheme_data().unwrap() {
|
let url = load_data.url.clone();
|
||||||
|
let non_relative_scheme_data = url.non_relative_scheme_data().unwrap();
|
||||||
|
match non_relative_scheme_data {
|
||||||
"blank" => {
|
"blank" => {
|
||||||
let metadata = Metadata {
|
let metadata = Metadata {
|
||||||
final_url: load_data.url,
|
final_url: load_data.url,
|
||||||
|
@ -34,9 +36,10 @@ pub fn factory(mut load_data: LoadData,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
"crash" => panic!("Loading the about:crash URL."),
|
"crash" => panic!("Loading the about:crash URL."),
|
||||||
"failure" => {
|
"failure" | "not-found" => {
|
||||||
let mut path = resources_dir_path();
|
let mut path = resources_dir_path();
|
||||||
path.push("failure.html");
|
let file_name = non_relative_scheme_data.to_owned() + ".html";
|
||||||
|
path.push(&file_name);
|
||||||
assert!(path.exists());
|
assert!(path.exists());
|
||||||
load_data.url = Url::from_file_path(&*path).unwrap();
|
load_data.url = Url::from_file_path(&*path).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use about_loader;
|
||||||
use mime_classifier::MIMEClassifier;
|
use mime_classifier::MIMEClassifier;
|
||||||
use net_traits::ProgressMsg::{Done, Payload};
|
use net_traits::ProgressMsg::{Done, Payload};
|
||||||
use net_traits::{LoadConsumer, LoadData, Metadata};
|
use net_traits::{LoadConsumer, LoadData, Metadata};
|
||||||
|
@ -13,6 +14,7 @@ use std::fs::File;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use url::Url;
|
||||||
use util::task::spawn_named;
|
use util::task::spawn_named;
|
||||||
|
|
||||||
static READ_SIZE: usize = 8192;
|
static READ_SIZE: usize = 8192;
|
||||||
|
@ -96,8 +98,13 @@ pub fn factory(load_data: LoadData,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(_) => {
|
||||||
send_error(url, e.description().to_owned(), senders);
|
// this should be one of the three errors listed in
|
||||||
|
// http://doc.rust-lang.org/std/fs/struct.OpenOptions.html#method.open
|
||||||
|
// but, we'll go for a "file not found!"
|
||||||
|
let url = Url::parse("about:not-found").unwrap();
|
||||||
|
let load_data_404 = LoadData::new(url, None);
|
||||||
|
about_loader::factory(load_data_404, senders, classifier, cancel_listener)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
9
resources/not-found.html
Normal file
9
resources/not-found.html
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>about:not-found</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<!-- courtesy of https://mozillians.org/blahblah -->
|
||||||
|
<img src="tumbeast.png">
|
||||||
|
</body>
|
||||||
|
</html>
|
BIN
resources/tumbeast.png
Normal file
BIN
resources/tumbeast.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
Loading…
Add table
Add a link
Reference in a new issue