Skip to content

Commit 0cda953

Browse files
author
Justin Pflueger
committed
adjusting for PR feedback
Signed-off-by: Justin Pflueger <[email protected]>
1 parent c8f5d4e commit 0cda953

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

src/lib.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -80,23 +80,18 @@ fn serve(req: Request) -> Result<Response> {
8080
};
8181

8282
// read from the fallback path if the variable exists
83-
let read_result = match std::env::var(FALLBACK_PATH_ENV) {
84-
Ok(fallback_path) => {
85-
println!("Fallback Path: {fallback_path:?}");
86-
FileServer::read(path, &enc).or_else(|_| FileServer::read(fallback_path.as_str(), &enc))
87-
}
88-
Err(e) => {
89-
eprintln!("Cannot read env var: {e:?}");
90-
FileServer::read(path, &enc)
91-
}
92-
};
93-
94-
let body = match read_result {
83+
let body = match FileServer::read(path, &enc) {
84+
// requested file was found
9585
Ok(b) => Some(b),
96-
Err(e) => {
97-
eprintln!("Cannot read file: {e:?}");
98-
return not_found();
99-
}
86+
Err(e) => match std::env::var(FALLBACK_PATH_ENV) {
87+
// try to read the fallback path
88+
Ok(fallback_path) => FileServer::read(fallback_path.as_str(), &enc).ok(),
89+
// fallback path config not found
90+
Err(_) => {
91+
eprintln!("Cannot read file: {:?}", e);
92+
None
93+
}
94+
},
10095
};
10196

10297
let etag = FileServer::get_etag(body.clone());
@@ -163,10 +158,14 @@ impl FileServer {
163158
.ok_or(anyhow!("cannot get headers for response"))?;
164159
FileServer::append_headers(path, enc, etag, headers)?;
165160

166-
if etag == if_none_match {
167-
return Ok(res.status(StatusCode::NOT_MODIFIED).body(None)?);
161+
if body.is_some() {
162+
if etag == if_none_match {
163+
return Ok(res.status(StatusCode::NOT_MODIFIED).body(None)?);
164+
}
165+
Ok(res.status(StatusCode::OK).body(body)?)
166+
} else {
167+
not_found()
168168
}
169-
Ok(res.status(StatusCode::OK).body(body)?)
170169
}
171170

172171
fn get_etag(body: Option<Bytes>) -> String {

0 commit comments

Comments
 (0)