Skip to content

Commit c050d07

Browse files
committed
Format for style changes
1 parent 30610e0 commit c050d07

File tree

1 file changed

+40
-23
lines changed

1 file changed

+40
-23
lines changed

core/lib/src/fs/server.rs

+40-23
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ impl fmt::Debug for DebugListRewrite<'_> {
9595

9696
pub trait Rewrite: Send + Sync + Any {
9797
/// Modify RewritablePath as needed.
98-
fn rewrite(&self, req: &Request<'_>, path: FileServerResponse, root: &Path) -> FileServerResponse;
98+
fn rewrite(&self, req: &Request<'_>, path: FileServerResponse, root: &Path)
99+
-> FileServerResponse;
99100
/// Allow multiple of the same rewrite
100101
fn allow_multiple(&self) -> bool { false }
101102
fn name(&self) -> &'static str{ type_name::<Self>()}
@@ -129,9 +130,12 @@ pub enum FileServerResponse {
129130
// These might have to remain as basic options (always processed first)
130131
struct DotFiles;
131132
impl Rewrite for DotFiles {
132-
fn rewrite(&self, _req: &Request<'_>, path: FileServerResponse, _root: &Path) -> FileServerResponse {
133+
fn rewrite(&self, _req: &Request<'_>, path: FileServerResponse, _root: &Path)
134+
-> FileServerResponse
135+
{
133136
match path {
134-
FileServerResponse::Hidden { name, reason: HiddenReason::DotFile } => FileServerResponse::File { name, modified: None, headers: HeaderMap::new() },
137+
FileServerResponse::Hidden { name, reason: HiddenReason::DotFile } =>
138+
FileServerResponse::File { name, modified: None, headers: HeaderMap::new() },
135139
path => path,
136140
}
137141
}
@@ -145,35 +149,37 @@ impl Rewrite for DotFiles {
145149

146150
struct Index(&'static str);
147151
impl Rewrite for Index {
148-
fn rewrite(&self, _req: &Request<'_>, path: FileServerResponse, root: &Path) -> FileServerResponse {
149-
// if path.file_name_path.is_dir() {
150-
// path.file_name_path.push(self.0);
151-
// // TODO: handle file_data_path
152-
// }
152+
fn rewrite(&self, _req: &Request<'_>, path: FileServerResponse, root: &Path)
153+
-> FileServerResponse
154+
{
153155
match path {
154-
FileServerResponse::File { name, modified, headers } if root.join(&name).is_dir() => FileServerResponse::File { name: name.join(self.0), modified, headers },
156+
FileServerResponse::File { name, modified, headers } if root.join(&name).is_dir() =>
157+
FileServerResponse::File { name: name.join(self.0), modified, headers },
155158
path => path,
156159
}
157160
}
158161
}
159-
// Actually, curiously, this already just works as-is (the only thing that prevents it is the startup check)
162+
// Actually, curiously, this already just works as-is (the only thing that prevents
163+
// it is the startup check)
160164
struct IndexFile;
161165
impl Rewrite for IndexFile {
162-
fn rewrite(&self, _req: &Request<'_>, path: FileServerResponse, _root: &Path) -> FileServerResponse {
166+
fn rewrite(&self, _req: &Request<'_>, path: FileServerResponse, _root: &Path)
167+
-> FileServerResponse
168+
{
163169
match path {
164-
// FileServerResponse::File { name, modified, headers } if _root.is_file() && name.iter().count() == 0 => {
165-
// FileServerResponse::File { name, modified, headers }
166-
// }
167170
path => path,
168171
}
169172
}
170173
}
171174

172175
struct NormalizeDirs;
173176
impl Rewrite for NormalizeDirs {
174-
fn rewrite(&self, req: &Request<'_>, path: FileServerResponse, root: &Path) -> FileServerResponse {
177+
fn rewrite(&self, req: &Request<'_>, path: FileServerResponse, root: &Path)
178+
-> FileServerResponse
179+
{
175180
match path {
176-
FileServerResponse::File { name, .. } if !req.uri().path().ends_with('/') && root.join(&name).is_dir() =>
181+
FileServerResponse::File { name, .. } if !req.uri().path().ends_with('/') &&
182+
root.join(&name).is_dir() =>
177183
FileServerResponse::PermanentRedirect {
178184
to: req.uri().map_path(|p| format!("{}/", p))
179185
.expect("adding a trailing slash to a known good path => valid path")
@@ -301,10 +307,14 @@ impl FileServer {
301307
}
302308

303309
pub fn rewrite(mut self, rewrite: impl Rewrite) -> Self {
304-
if rewrite.allow_multiple() || !self.rewrites.iter().any(|f| f.as_ref().type_id() == rewrite.type_id()) {
310+
if rewrite.allow_multiple() ||
311+
!self.rewrites .iter().any(|f| f.as_ref().type_id() == rewrite.type_id()) {
305312
self.rewrites.push(Arc::new(rewrite));
306313
} else {
307-
error!("Attempted to insert multiple of the same rewrite `{}` on a FileServer", rewrite.name());
314+
error!(
315+
"Attempted to insert multiple of the same rewrite `{}` on a FileServer",
316+
rewrite.name()
317+
);
308318
}
309319
self
310320
}
@@ -346,8 +356,10 @@ impl Handler for FileServer {
346356
.and_then(|segments| segments.to_path_buf_dotfiles().ok());
347357
// .map(|path| self.root.join(path));
348358
let mut response = match path {
349-
Some((name, false)) => FileServerResponse::File { name, modified: None, headers: HeaderMap::new() },
350-
Some((name, true)) => FileServerResponse::Hidden { name, reason: HiddenReason::DotFile },
359+
Some((name, false)) =>
360+
FileServerResponse::File { name, modified: None, headers: HeaderMap::new() },
361+
Some((name, true)) =>
362+
FileServerResponse::Hidden { name, reason: HiddenReason::DotFile },
351363
None => return Outcome::forward(data, Status::NotFound),
352364
};
353365
println!("initial: {response:?}");
@@ -372,9 +384,14 @@ impl Handler for FileServer {
372384
r
373385
}).or_forward((data, Status::NotFound))
374386
},
375-
FileServerResponse::Hidden { .. } | FileServerResponse::NotFound { ..} => Outcome::forward(data, Status::NotFound),
376-
FileServerResponse::PermanentRedirect { to } => Redirect::permanent(to).respond_to(req).or_forward((data, Status::InternalServerError)),
377-
FileServerResponse::TemporaryRedirect { to } => Redirect::temporary(to).respond_to(req).or_forward((data, Status::InternalServerError)),
387+
FileServerResponse::Hidden { .. } | FileServerResponse::NotFound { ..} =>
388+
Outcome::forward(data, Status::NotFound),
389+
FileServerResponse::PermanentRedirect { to } => Redirect::permanent(to)
390+
.respond_to(req)
391+
.or_forward((data, Status::InternalServerError)),
392+
FileServerResponse::TemporaryRedirect { to } => Redirect::temporary(to)
393+
.respond_to(req)
394+
.or_forward((data, Status::InternalServerError)),
378395
}
379396
}
380397
}

0 commit comments

Comments
 (0)