Skip to content

Commit c7bdf2e

Browse files
committed
bakg
1 parent 99030b8 commit c7bdf2e

File tree

4 files changed

+34
-32
lines changed

4 files changed

+34
-32
lines changed

.github/workflows/spa-server-ci.yml

+5-7
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,15 @@ jobs:
2828
with:
2929
path: ~/.cargo/git
3030
key: cargo-index-trimmed-${{ hashFiles('**/Cargo.lock') }}
31-
- name: build all
32-
run: cargo build
33-
- name: run spa-client test
34-
run: cargo test -p spa-client
35-
- name: run spa-client test
36-
run: cargo test -p spa-server
3731
- name: run integration test
3832
# --show-output
3933
run: cargo test -p tests --test starter -j 1 -- --test-threads 1
4034
- name: run pebble
4135
run: ./run_pebble.sh
4236
working-directory: ./tests/bash/
4337
- name: run acme integration test
44-
run: cargo test -p tests --test acme_test -j 1 -- --test-threads 1
38+
run: cargo test -p tests --test acme_test -j 1 -- --test-threads 1
39+
- name: run spa-client test
40+
run: cargo test -p spa-client
41+
- name: run spa-client test
42+
run: cargo test -p spa-server

server/src/file_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ impl FileCache {
233233
.cloned();
234234
if let Some(v) = index_opt {
235235
result.insert(format!("{key_prefix}/"), v.clone());
236-
// result.insert(key_prefix.to_string(), v);
236+
// result.insert(key_prefix.to_string(), v); //GitHub Action CI would trigger This, but I could not trigger this in my compute
237237
}
238238
}
239239
None => {

server/src/service.rs

+20-16
Original file line numberDiff line numberDiff line change
@@ -103,22 +103,10 @@ pub async fn create_service(
103103
return Ok(resp);
104104
}
105105
}
106-
// path: "" => "/"
107-
if domain_storage.check_if_empty_index(host, path) {
108-
let mut resp = Response::default();
109-
let mut path = format!("{path}/");
110-
if let Some(query) = uri.query() {
111-
path.push('?');
112-
path.push_str(query);
113-
}
114-
let path = path.parse().unwrap();
115-
resp.headers_mut().insert(LOCATION, path);
116-
*resp.status_mut() = StatusCode::MOVED_PERMANENTLY;
117-
return Ok(resp);
118-
}
106+
119107
// static file
120-
let mut resp = match get_cache_file(path, host, domain_storage).await {
121-
Ok(item) => {
108+
let mut resp = match get_cache_file(path, host, domain_storage.clone()).await {
109+
Some(item) => {
122110
let headers = req.headers();
123111
let conditionals = Conditionals {
124112
if_modified_since: headers.typed_get(),
@@ -131,7 +119,23 @@ pub async fn create_service(
131119
.and_then(|x| x.to_str().map(|x| x.to_string()).ok());
132120
cache_or_file_reply(item, conditionals, accept_encoding).await
133121
}
134-
Err(resp) => Ok(resp),
122+
None => {
123+
// path: "" => "/"
124+
if domain_storage.check_if_empty_index(host, path) {
125+
let mut resp = Response::default();
126+
let mut path = format!("{path}/");
127+
if let Some(query) = uri.query() {
128+
path.push('?');
129+
path.push_str(query);
130+
}
131+
let path = path.parse().unwrap();
132+
resp.headers_mut().insert(LOCATION, path);
133+
*resp.status_mut() = StatusCode::MOVED_PERMANENTLY;
134+
Ok(resp)
135+
} else {
136+
Ok(not_found())
137+
}
138+
},
135139
};
136140

137141
if let Some(Validated::Simple(origin)) = origin_opt {

server/src/static_file_filter.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ use warp::fs::{file_stream, optimal_buf_size, Cond, Conditionals};
1919
use warp::http::{Response, StatusCode};
2020

2121
//from warp::fs
22-
fn sanitize_path(tail: &str) -> Result<String, Response<Body>> {
22+
fn sanitize_path(tail: &str) -> Option<String> {
2323
if let Ok(p) = percent_decode_str(tail).decode_utf8() {
2424
for seg in p.split('/') {
2525
if seg.starts_with("..") || seg.contains('\\') {
26-
return Err(not_found());
26+
return None
2727
}
2828
}
29-
Ok(p.into_owned())
29+
Some(p.into_owned())
3030
} else {
31-
Err(not_found())
31+
None
3232
}
3333
}
3434
#[derive(Debug)]
@@ -252,14 +252,14 @@ pub async fn get_cache_file(
252252
tail: &str,
253253
host: &str,
254254
domain_storage: Arc<DomainStorage>,
255-
) -> Result<(String, Arc<CacheItem>), Response<Body>> {
255+
) -> Option<(String, Arc<CacheItem>)> {
256256
let _key = sanitize_path(tail)?;
257257
let key = _key[1..].to_owned();
258258
debug!("get file: {host}, tail:{_key}, fixed: {key}");
259-
if let Some(cache_item) = domain_storage.get_file(host, &key) {
260-
Ok((key, cache_item))
259+
if let Some(cache_item) = domain_storage.get_file(host, &key) {
260+
Some((key, cache_item))
261261
} else {
262262
debug!("no file for: {}/{}", &host, &key);
263-
Err(not_found())
263+
None
264264
}
265265
}

0 commit comments

Comments
 (0)