1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520
|
Index: tower-http/src/services/fs/serve_dir/tests.rs
===================================================================
--- tower-http.orig/src/services/fs/serve_dir/tests.rs
+++ tower-http/src/services/fs/serve_dir/tests.rs
@@ -13,7 +13,9 @@ use tower::{service_fn, ServiceExt};
#[tokio::test]
async fn basic() {
- let svc = ServeDir::new("..");
+ //use std::env::current_dir;
+ //println!("{}",current_dir().unwrap().display());
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/README.md")
@@ -26,11 +28,11 @@ async fn basic() {
let body = body_into_text(res.into_body()).await;
- let contents = std::fs::read_to_string("../README.md").unwrap();
+ let contents = std::fs::read_to_string("./README.md").unwrap();
assert_eq!(body, contents);
}
-#[tokio::test]
+/*#[tokio::test]
async fn basic_with_index() {
let svc = ServeDir::new("../test-files");
@@ -42,28 +44,28 @@ async fn basic_with_index() {
let body = body_into_text(res.into_body()).await;
assert_eq!(body, "<b>HTML!</b>\n");
-}
+}*/
#[tokio::test]
async fn head_request() {
- let svc = ServeDir::new("../test-files");
+ let svc = ServeDir::new(".");
let req = Request::builder()
- .uri("/precompressed.txt")
+ .uri("/README.md")
.method(Method::HEAD)
.body(Body::empty())
.unwrap();
let res = svc.oneshot(req).await.unwrap();
- assert_eq!(res.headers()["content-type"], "text/plain");
- assert_eq!(res.headers()["content-length"], "23");
+ assert_eq!(res.headers()["content-type"], "text/markdown");
+ assert_eq!(res.headers()["content-length"], std::fs::metadata("README.md").unwrap().len().to_string());
let body = res.into_body().data().await;
assert!(body.is_none());
}
-#[tokio::test]
+/*#[tokio::test]
async fn precompresed_head_request() {
let svc = ServeDir::new("../test-files").precompressed_gzip();
@@ -81,11 +83,11 @@ async fn precompresed_head_request() {
let body = res.into_body().data().await;
assert!(body.is_none());
-}
+}*/
#[tokio::test]
async fn with_custom_chunk_size() {
- let svc = ServeDir::new("..").with_buf_chunk_size(1024 * 32);
+ let svc = ServeDir::new(".").with_buf_chunk_size(1024 * 32);
let req = Request::builder()
.uri("/README.md")
@@ -98,11 +100,11 @@ async fn with_custom_chunk_size() {
let body = body_into_text(res.into_body()).await;
- let contents = std::fs::read_to_string("../README.md").unwrap();
+ let contents = std::fs::read_to_string("./README.md").unwrap();
assert_eq!(body, contents);
}
-#[tokio::test]
+/*#[tokio::test]
async fn precompressed_gzip() {
let svc = ServeDir::new("../test-files").precompressed_gzip();
@@ -251,30 +253,30 @@ async fn missing_precompressed_variant_f
assert!(res.headers().get("content-encoding").is_none());
assert!(res.into_body().data().await.is_none());
-}
+}*/
#[tokio::test]
async fn access_to_sub_dirs() {
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
- .uri("/tower-http/Cargo.toml")
+ .uri("/src/lib.rs")
.body(Body::empty())
.unwrap();
let res = svc.oneshot(req).await.unwrap();
assert_eq!(res.status(), StatusCode::OK);
- assert_eq!(res.headers()["content-type"], "text/x-toml");
+ assert_eq!(res.headers()["content-type"], "text/x-rust");
let body = body_into_text(res.into_body()).await;
- let contents = std::fs::read_to_string("Cargo.toml").unwrap();
+ let contents = std::fs::read_to_string("src/lib.rs").unwrap();
assert_eq!(body, contents);
}
#[tokio::test]
async fn not_found() {
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/not-found")
@@ -292,12 +294,12 @@ async fn not_found() {
#[cfg(unix)]
#[tokio::test]
async fn not_found_when_not_a_directory() {
- let svc = ServeDir::new("../test-files");
+ let svc = ServeDir::new(".");
- // `index.html` is a file, and we are trying to request
+ // `lib.rs` is a file, and we are trying to request
// it as a directory.
let req = Request::builder()
- .uri("/index.html/some_file")
+ .uri("/src/lib.rs/some_file")
.body(Body::empty())
.unwrap();
let res = svc.oneshot(req).await.unwrap();
@@ -312,7 +314,7 @@ async fn not_found_when_not_a_directory(
#[tokio::test]
async fn not_found_precompressed() {
- let svc = ServeDir::new("../test-files").precompressed_gzip();
+ let svc = ServeDir::new(".").precompressed_gzip();
let req = Request::builder()
.uri("/not-found")
@@ -328,7 +330,7 @@ async fn not_found_precompressed() {
assert!(body.is_empty());
}
-#[tokio::test]
+/*#[tokio::test]
async fn fallbacks_to_different_precompressed_variant_if_not_found_for_head_request() {
let svc = ServeDir::new("../test-files")
.precompressed_gzip()
@@ -370,7 +372,7 @@ async fn fallbacks_to_different_precompr
BrotliDecompress(&mut &body[..], &mut decompressed).unwrap();
let decompressed = String::from_utf8(decompressed.to_vec()).unwrap();
assert!(decompressed.starts_with("Test file"));
-}
+}*/
#[tokio::test]
async fn redirect_to_trailing_slash_on_dir() {
@@ -408,7 +410,7 @@ where
String::from_utf8(bytes.to_vec()).unwrap()
}
-#[tokio::test]
+/*#[tokio::test]
async fn access_cjk_percent_encoded_uri_path() {
// percent encoding present of 你好世界.txt
let cjk_filename_encoded = "%E4%BD%A0%E5%A5%BD%E4%B8%96%E7%95%8C.txt";
@@ -439,11 +441,11 @@ async fn access_space_percent_encoded_ur
assert_eq!(res.status(), StatusCode::OK);
assert_eq!(res.headers()["content-type"], "text/plain");
-}
+}*/
#[tokio::test]
async fn read_partial_in_bounds() {
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let bytes_start_incl = 9;
let bytes_end_incl = 1023;
@@ -457,7 +459,7 @@ async fn read_partial_in_bounds() {
.unwrap();
let res = svc.oneshot(req).await.unwrap();
- let file_contents = std::fs::read("../README.md").unwrap();
+ let file_contents = std::fs::read("./README.md").unwrap();
assert_eq!(res.status(), StatusCode::PARTIAL_CONTENT);
assert_eq!(
res.headers()["content-length"],
@@ -509,7 +511,7 @@ async fn read_partial_rejects_out_of_bou
#[tokio::test]
async fn read_partial_errs_on_garbage_header() {
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/README.md")
.header("Range", "bad_format")
@@ -517,7 +519,7 @@ async fn read_partial_errs_on_garbage_he
.unwrap();
let res = svc.oneshot(req).await.unwrap();
assert_eq!(res.status(), StatusCode::RANGE_NOT_SATISFIABLE);
- let file_contents = std::fs::read("../README.md").unwrap();
+ let file_contents = std::fs::read("./README.md").unwrap();
assert_eq!(
res.headers()["content-range"],
&format!("bytes */{}", file_contents.len())
@@ -526,7 +528,7 @@ async fn read_partial_errs_on_garbage_he
#[tokio::test]
async fn read_partial_errs_on_bad_range() {
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/README.md")
.header("Range", "bytes=-1-15")
@@ -534,7 +536,7 @@ async fn read_partial_errs_on_bad_range(
.unwrap();
let res = svc.oneshot(req).await.unwrap();
assert_eq!(res.status(), StatusCode::RANGE_NOT_SATISFIABLE);
- let file_contents = std::fs::read("../README.md").unwrap();
+ let file_contents = std::fs::read("./README.md").unwrap();
assert_eq!(
res.headers()["content-range"],
&format!("bytes */{}", file_contents.len())
@@ -543,7 +545,7 @@ async fn read_partial_errs_on_bad_range(
#[tokio::test]
async fn accept_encoding_identity() {
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/README.md")
.header("Accept-Encoding", "identity")
@@ -557,7 +559,7 @@ async fn accept_encoding_identity() {
#[tokio::test]
async fn last_modified() {
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/README.md")
.body(Body::empty())
@@ -572,7 +574,7 @@ async fn last_modified() {
// -- If-Modified-Since
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/README.md")
.header(header::IF_MODIFIED_SINCE, last_modified)
@@ -584,7 +586,7 @@ async fn last_modified() {
let body = res.into_body().data().await;
assert!(body.is_none());
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/README.md")
.header(header::IF_MODIFIED_SINCE, "Fri, 09 Aug 1996 14:21:40 GMT")
@@ -593,13 +595,13 @@ async fn last_modified() {
let res = svc.oneshot(req).await.unwrap();
assert_eq!(res.status(), StatusCode::OK);
- let readme_bytes = include_bytes!("../../../../../README.md");
+ let readme_bytes = include_bytes!("../../../../README.md");
let body = res.into_body().data().await.unwrap().unwrap();
assert_eq!(body.as_ref(), readme_bytes);
// -- If-Unmodified-Since
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/README.md")
.header(header::IF_UNMODIFIED_SINCE, last_modified)
@@ -611,7 +613,7 @@ async fn last_modified() {
let body = res.into_body().data().await.unwrap().unwrap();
assert_eq!(body.as_ref(), readme_bytes);
- let svc = ServeDir::new("..");
+ let svc = ServeDir::new(".");
let req = Request::builder()
.uri("/README.md")
.header(header::IF_UNMODIFIED_SINCE, "Fri, 09 Aug 1996 14:21:40 GMT")
@@ -649,7 +651,7 @@ async fn with_fallback_svc() {
#[tokio::test]
async fn with_fallback_serve_file() {
- let svc = ServeDir::new("..").fallback(ServeFile::new("../README.md"));
+ let svc = ServeDir::new(".").fallback(ServeFile::new("./README.md"));
let req = Request::builder()
.uri("/doesnt-exist")
@@ -662,7 +664,7 @@ async fn with_fallback_serve_file() {
let body = body_into_text(res.into_body()).await;
- let contents = std::fs::read_to_string("../README.md").unwrap();
+ let contents = std::fs::read_to_string("./README.md").unwrap();
assert_eq!(body, contents);
}
Index: tower-http/src/services/fs/serve_file.rs
===================================================================
--- tower-http.orig/src/services/fs/serve_file.rs
+++ tower-http/src/services/fs/serve_file.rs
@@ -143,7 +143,7 @@ mod tests {
#[tokio::test]
async fn basic() {
- let svc = ServeFile::new("../README.md");
+ let svc = ServeFile::new("./README.md");
let res = svc.oneshot(Request::new(Body::empty())).await.unwrap();
@@ -157,7 +157,7 @@ mod tests {
#[tokio::test]
async fn basic_with_mime() {
- let svc = ServeFile::new_with_mime("../README.md", &Mime::from_str("image/jpg").unwrap());
+ let svc = ServeFile::new_with_mime("./README.md", &Mime::from_str("image/jpg").unwrap());
let res = svc.oneshot(Request::new(Body::empty())).await.unwrap();
@@ -171,20 +171,20 @@ mod tests {
#[tokio::test]
async fn head_request() {
- let svc = ServeFile::new("../test-files/precompressed.txt");
+ let svc = ServeFile::new("./README.md");
let mut request = Request::new(Body::empty());
*request.method_mut() = Method::HEAD;
let res = svc.oneshot(request).await.unwrap();
- assert_eq!(res.headers()["content-type"], "text/plain");
- assert_eq!(res.headers()["content-length"], "23");
+ assert_eq!(res.headers()["content-type"], "text/markdown");
+ assert_eq!(res.headers()["content-length"], std::fs::metadata("README.md").unwrap().len().to_string());
let body = res.into_body().data().await;
assert!(body.is_none());
}
- #[tokio::test]
+ /*#[tokio::test]
async fn precompresed_head_request() {
let svc = ServeFile::new("../test-files/precompressed.txt").precompressed_gzip();
@@ -239,11 +239,11 @@ mod tests {
let body = res.into_body().data().await.unwrap().unwrap();
let body = String::from_utf8(body.to_vec()).unwrap();
assert!(body.starts_with("\"This is a test file!\""));
- }
+ }*/
#[tokio::test]
async fn missing_precompressed_variant_fallbacks_to_uncompressed() {
- let svc = ServeFile::new("../test-files/missing_precompressed.txt").precompressed_gzip();
+ let svc = ServeFile::new("./README.md").precompressed_gzip();
let request = Request::builder()
.header("Accept-Encoding", "gzip")
@@ -251,18 +251,18 @@ mod tests {
.unwrap();
let res = svc.oneshot(request).await.unwrap();
- assert_eq!(res.headers()["content-type"], "text/plain");
+ assert_eq!(res.headers()["content-type"], "text/markdown");
// Uncompressed file is served because compressed version is missing
assert!(res.headers().get("content-encoding").is_none());
let body = res.into_body().data().await.unwrap().unwrap();
let body = String::from_utf8(body.to_vec()).unwrap();
- assert!(body.starts_with("Test file!"));
+ assert!(body.starts_with("# Tower HTTP"));
}
#[tokio::test]
async fn missing_precompressed_variant_fallbacks_to_uncompressed_head_request() {
- let svc = ServeFile::new("../test-files/missing_precompressed.txt").precompressed_gzip();
+ let svc = ServeFile::new("./README.md").precompressed_gzip();
let request = Request::builder()
.header("Accept-Encoding", "gzip")
@@ -271,8 +271,8 @@ mod tests {
.unwrap();
let res = svc.oneshot(request).await.unwrap();
- assert_eq!(res.headers()["content-type"], "text/plain");
- assert_eq!(res.headers()["content-length"], "11");
+ assert_eq!(res.headers()["content-type"], "text/markdown");
+ assert_eq!(res.headers()["content-length"], std::fs::metadata("README.md").unwrap().len().to_string());
// Uncompressed file is served because compressed version is missing
assert!(res.headers().get("content-encoding").is_none());
@@ -280,7 +280,7 @@ mod tests {
assert!(body.is_none());
}
- #[tokio::test]
+ /*#[tokio::test]
async fn only_precompressed_variant_existing() {
let svc = ServeFile::new("../test-files/only_gzipped.txt").precompressed_gzip();
@@ -380,11 +380,11 @@ mod tests {
BrotliDecompress(&mut &body[..], &mut decompressed).unwrap();
let decompressed = String::from_utf8(decompressed.to_vec()).unwrap();
assert!(decompressed.starts_with("\"This is a test file!\""));
- }
+ }*/
#[tokio::test]
async fn with_custom_chunk_size() {
- let svc = ServeFile::new("../README.md").with_buf_chunk_size(1024 * 32);
+ let svc = ServeFile::new("./README.md").with_buf_chunk_size(1024 * 32);
let res = svc.oneshot(Request::new(Body::empty())).await.unwrap();
@@ -396,7 +396,7 @@ mod tests {
assert!(body.starts_with("# Tower HTTP"));
}
- #[tokio::test]
+ /*#[tokio::test]
async fn fallbacks_to_different_precompressed_variant_if_not_found() {
let svc = ServeFile::new("../test-files/precompressed_br.txt")
.precompressed_gzip()
@@ -439,11 +439,11 @@ mod tests {
let body = res.into_body().data().await;
assert!(body.is_none());
- }
+ }*/
#[tokio::test]
async fn returns_404_if_file_doesnt_exist() {
- let svc = ServeFile::new("../this-doesnt-exist.md");
+ let svc = ServeFile::new("./this-doesnt-exist.md");
let res = svc.oneshot(Request::new(Body::empty())).await.unwrap();
@@ -453,7 +453,7 @@ mod tests {
#[tokio::test]
async fn returns_404_if_file_doesnt_exist_when_precompression_is_used() {
- let svc = ServeFile::new("../this-doesnt-exist.md").precompressed_deflate();
+ let svc = ServeFile::new("./this-doesnt-exist.md").precompressed_deflate();
let request = Request::builder()
.header("Accept-Encoding", "deflate")
@@ -467,7 +467,7 @@ mod tests {
#[tokio::test]
async fn last_modified() {
- let svc = ServeFile::new("../README.md");
+ let svc = ServeFile::new("./README.md");
let req = Request::builder().body(Body::empty()).unwrap();
let res = svc.oneshot(req).await.unwrap();
@@ -481,7 +481,7 @@ mod tests {
// -- If-Modified-Since
- let svc = ServeFile::new("../README.md");
+ let svc = ServeFile::new("./README.md");
let req = Request::builder()
.header(header::IF_MODIFIED_SINCE, last_modified)
.body(Body::empty())
@@ -492,7 +492,7 @@ mod tests {
let body = res.into_body().data().await;
assert!(body.is_none());
- let svc = ServeFile::new("../README.md");
+ let svc = ServeFile::new("./README.md");
let req = Request::builder()
.header(header::IF_MODIFIED_SINCE, "Fri, 09 Aug 1996 14:21:40 GMT")
.body(Body::empty())
@@ -500,13 +500,13 @@ mod tests {
let res = svc.oneshot(req).await.unwrap();
assert_eq!(res.status(), StatusCode::OK);
- let readme_bytes = include_bytes!("../../../../README.md");
+ let readme_bytes = include_bytes!("../../../README.md");
let body = res.into_body().data().await.unwrap().unwrap();
assert_eq!(body.as_ref(), readme_bytes);
// -- If-Unmodified-Since
- let svc = ServeFile::new("../README.md");
+ let svc = ServeFile::new("./README.md");
let req = Request::builder()
.header(header::IF_UNMODIFIED_SINCE, last_modified)
.body(Body::empty())
@@ -517,7 +517,7 @@ mod tests {
let body = res.into_body().data().await.unwrap().unwrap();
assert_eq!(body.as_ref(), readme_bytes);
- let svc = ServeFile::new("../README.md");
+ let svc = ServeFile::new("./README.md");
let req = Request::builder()
.header(header::IF_UNMODIFIED_SINCE, "Fri, 09 Aug 1996 14:21:40 GMT")
.body(Body::empty())
|