Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added local directory listing feature. #32167

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ surfman = { version = "0.9", features = ["chains", "sm-angle", "sm-angle-default
syn = { version = "2", default-features = false, features = ["clone-impls", "derive", "parsing"] }
synstructure = "0.13"
thin-vec = "0.2.13"
# TODO: Migrate Servo from time 0.1 to 0.3 so that we don't need to build both versions.
time = "0.1.41"
time_03 = { package = "time", version = "0.3 ", features = ["std", "local-offset"] }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to avoid further use of this crate, see #30150

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue #30150 suggests replacing the old "time" dependency with one of these alternatives:

  • std::time - I don't think this makes it possible to format a filesystem timestamp into a readable datetime;
  • chrono - this does implement From<std::time::SystemTime> so it might be suitable, but I don't see "chrono" already listed in the main Cargo.toml file;
  • time (latest version) - this is what I've used already, by adding the alias "time_03" to the Cargo.toml file.

Can you (or @mrobinson) tell me which is the preferred approach?

to_shmem = { git = "https://github.com/servo/stylo", branch = "2024-05-15" }
tokio = "1"
tokio-rustls = "0.24"
Expand Down
5 changes: 4 additions & 1 deletion components/config/prefs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ mod gen {
background_color: i64,
#[serde(default = "black")]
foreground_color: i64,
}
},
},
css: {
animations: {
Expand Down Expand Up @@ -548,6 +548,9 @@ mod gen {
#[serde(rename = "network.http-cache.disabled")]
disabled: bool,
},
local_directory_listing: {
enabled: bool,
},
mime: {
sniff: bool,
}
Expand Down
2 changes: 2 additions & 0 deletions components/net/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ servo_config = { path = "../config" }
servo_url = { path = "../url" }
sha2 = "0.10"
time = { workspace = true }
time_03 = { workspace = true }
tokio = { workspace = true, features = ["sync", "macros", "rt-multi-thread"] }
tokio-rustls = { workspace = true }
tokio-stream = "0.1"
Expand All @@ -73,6 +74,7 @@ futures = { version = "0.3", features = ["compat"] }
tokio-test = "0.4"
tokio-stream = { version = "0.1", features = ["net"] }
hyper = { workspace = true, features = ["full"] }
tempfile = "3"

[[test]]
name = "main"
Expand Down
9 changes: 5 additions & 4 deletions components/net/fetch/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use crate::http_loader::{
determine_requests_referrer, http_fetch, set_default_accept, set_default_accept_language,
HttpState,
};
use crate::local_directory_listing;
use crate::subresource_integrity::is_response_integrity_valid;

lazy_static! {
Expand Down Expand Up @@ -689,7 +690,6 @@ async fn scheme_fetch(
context: &FetchContext,
) -> Response {
let url = request.current_url();

match url.scheme() {
"about" if url.path() == "blank" => create_blank_reply(url, request.timing_type()),

Expand Down Expand Up @@ -732,9 +732,10 @@ async fn scheme_fetch(
if let Ok(file) = File::open(file_path.clone()) {
if let Ok(metadata) = file.metadata() {
if metadata.is_dir() {
return Response::network_error(NetworkError::Internal(
"Opening a directory is not supported".into(),
));
return match local_directory_listing::is_request_allowed(request) {
Err(refusal) => refusal,
Ok(()) => local_directory_listing::fetch(request, url, file_path),
};
}
}

Expand Down
1 change: 1 addition & 0 deletions components/net/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod hsts;
pub mod http_cache;
pub mod http_loader;
pub mod image_cache;
pub mod local_directory_listing;
pub mod mime_classifier;
pub mod resource_thread;
mod storage_thread;
Expand Down