1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-11-30 18:44:35 +01:00
actix-web/actix-files/tests/encoding.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

use actix_files::Files;
use actix_web::{
http::{
header::{self, HeaderValue},
StatusCode,
},
test::{self, TestRequest},
App,
};
2021-10-19 18:30:32 +02:00
#[actix_web::test]
async fn test_utf8_file_contents() {
// use default ISO-8859-1 encoding
let srv = test::init_service(App::new().service(Files::new("/", "./tests"))).await;
let req = TestRequest::with_uri("/utf8.txt").to_request();
let res = test::call_service(&srv, req).await;
assert_eq!(res.status(), StatusCode::OK);
assert_eq!(
res.headers().get(header::CONTENT_TYPE),
2022-01-12 18:53:36 +01:00
Some(&HeaderValue::from_static("text/plain; charset=utf-8")),
);
2022-01-12 18:53:36 +01:00
// disable UTF-8 attribute
2021-02-12 00:03:17 +01:00
let srv =
2022-01-12 18:53:36 +01:00
test::init_service(App::new().service(Files::new("/", "./tests").prefer_utf8(false)))
2021-02-12 00:03:17 +01:00
.await;
let req = TestRequest::with_uri("/utf8.txt").to_request();
let res = test::call_service(&srv, req).await;
assert_eq!(res.status(), StatusCode::OK);
assert_eq!(
res.headers().get(header::CONTENT_TYPE),
2022-01-12 18:53:36 +01:00
Some(&HeaderValue::from_static("text/plain")),
);
}