13. URL のハンドリング
HTML ファイルを読み込み,それをbodyに入れてレスポンスを返す
if req.head.path == "hello" {
let content = read_html("./src/static/assets/html/hello.html");
return Response::builder()
.status(StatusCode::Ok)
.content_type(Mime::Html)
.content_length(len2str(&content))
.body(content)
.build();
}
14. URL のハンドリング
HTML ファイルを読み込み,それをbodyに入れてレスポンスを返す
fn read_html(path: &'static str) -> String {
let f = File::open(path).expect("failed to open file.");
let mut lines = String::new();
BufReader::new(f).read_to_string(&mut lines).expect(
"failed to read file.",
);
lines
}