-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathmime.rs
More file actions
56 lines (50 loc) · 1.76 KB
/
Copy pathmime.rs
File metadata and controls
56 lines (50 loc) · 1.76 KB
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
#[cfg(features = "fs")]
mod tests {
use async_std::fs;
use async_std::io;
use http_types::{mime, Body, Response};
#[async_std::test]
async fn guess_plain_text_mime() -> io::Result<()> {
let body = Body::from_file("tests/fixtures/index.html").await?;
let mut res = Response::new(200);
res.set_body(body);
assert_eq!(res.content_type(), Some(mime::HTML));
Ok(())
}
#[async_std::test]
async fn guess_binary_mime() -> http_types::Result<()> {
let body = Body::from_file("tests/fixtures/nori.png").await?;
let mut res = Response::new(200);
res.set_body(body);
assert_eq!(res.content_type(), Some(mime::PNG));
// Assert the file is correctly reset after we've peeked the bytes
let left = fs::read("tests/fixtures/nori.png").await?;
let right = res.body_bytes().await?;
assert_eq!(left, right);
Ok(())
}
#[async_std::test]
async fn guess_mime_fallback() -> io::Result<()> {
let body = Body::from_file("tests/fixtures/unknown.custom").await?;
let mut res = Response::new(200);
res.set_body(body);
assert_eq!(res.content_type(), Some(mime::BYTE_STREAM));
Ok(())
}
#[async_std::test]
async fn parse_empty_files() -> http_types::Result<()> {
let body = Body::from_file("tests/fixtures/empty.custom").await?;
let mut res = Response::new(200);
res.set_body(body);
assert_eq!(res.content_type(), Some(mime::BYTE_STREAM));
Ok(())
}
// #[test]
// fn match_mime_types() {
// let req = Request::get("https://example.com");
// match req.content_type() {
// Some(mime::JSON) => {}
// _ => {}
// }
// }
}