~repos /rust-embed

#rust#proc-macro#http

git clone https://pyrossh.dev/repos/rust-embed.git

rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.


aec2df0f pyros2097

7 years ago
fix content type issues
Files changed (1) hide show
  1. examples/rocket.rs +4 -3
examples/rocket.rs CHANGED
@@ -5,6 +5,7 @@ extern crate rocket_contrib;
5
5
  extern crate rust_embed;
6
6
 
7
7
  use std::path::PathBuf;
8
+ use std::ffi::OsStr;
8
9
  use std::io::Cursor;
9
10
  use rocket::response;
10
11
  use rocket::http::{ContentType, Status};
@@ -28,13 +29,13 @@ fn index<'r>() -> response::Result<'r> {
28
29
  fn dist<'r>(file: PathBuf) -> response::Result<'r> {
29
30
  let filename = file.display().to_string();
30
31
  let asset = embed!("examples/public/".to_owned());
31
- // let ext = Path::new(&filename).extension().and_then(OsStr::to_str).expect("Could not get file extension");
32
+ let ext = file.as_path().extension().and_then(OsStr::to_str).expect("Could not get file extension");
32
- // let content_type = ContentType::from_extension(ext).expect("Could not get file content type");
33
+ let content_type = ContentType::from_extension(ext).expect("Could not get file content type");
33
34
  asset(filename.clone()).map_or_else(
34
35
  || Err(Status::NotFound),
35
36
  |d| {
36
37
  response::Response::build()
37
- .header(ContentType::HTML)
38
+ .header(content_type)
38
39
  .sized_body(Cursor::new(d))
39
40
  .ok()
40
41
  },