2020-10-06 22:56:28 +02:00
|
|
|
use actix_files::Files;
|
|
|
|
use actix_web::{
|
|
|
|
http::{
|
|
|
|
header::{self, HeaderValue},
|
|
|
|
StatusCode,
|
|
|
|
},
|
|
|
|
test::{self, TestRequest},
|
|
|
|
App,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn test_utf8_file_contents() {
|
|
|
|
// use default ISO-8859-1 encoding
|
2021-02-07 02:00:40 +01:00
|
|
|
let srv = test::init_service(App::new().service(Files::new("/", "./tests"))).await;
|
2020-10-06 22:56:28 +02:00
|
|
|
|
|
|
|
let req = TestRequest::with_uri("/utf8.txt").to_request();
|
2021-02-07 02:00:40 +01:00
|
|
|
let res = test::call_service(&srv, req).await;
|
2020-10-06 22:56:28 +02:00
|
|
|
|
|
|
|
assert_eq!(res.status(), StatusCode::OK);
|
|
|
|
assert_eq!(
|
|
|
|
res.headers().get(header::CONTENT_TYPE),
|
|
|
|
Some(&HeaderValue::from_static("text/plain")),
|
|
|
|
);
|
|
|
|
|
|
|
|
// prefer UTF-8 encoding
|
2021-02-12 00:03:17 +01:00
|
|
|
let srv =
|
|
|
|
test::init_service(App::new().service(Files::new("/", "./tests").prefer_utf8(true)))
|
|
|
|
.await;
|
2020-10-06 22:56:28 +02:00
|
|
|
|
|
|
|
let req = TestRequest::with_uri("/utf8.txt").to_request();
|
2021-02-07 02:00:40 +01:00
|
|
|
let res = test::call_service(&srv, req).await;
|
2020-10-06 22:56:28 +02:00
|
|
|
|
|
|
|
assert_eq!(res.status(), StatusCode::OK);
|
|
|
|
assert_eq!(
|
|
|
|
res.headers().get(header::CONTENT_TYPE),
|
|
|
|
Some(&HeaderValue::from_static("text/plain; charset=utf-8")),
|
|
|
|
);
|
|
|
|
}
|