maokwen commited on
Commit
4335749
Β·
unverified Β·
1 Parent(s): 1d97187

πŸ› fix: explicit Content-Type header for HTTP response (#457)

Browse files
Files changed (1) hide show
  1. src/server/router.rs +34 -28
src/server/router.rs CHANGED
@@ -12,14 +12,16 @@ use std::fs::read_to_string;
12
  /// Handles the route of index page or main page of the `websurfx` meta search engine website.
13
  #[get("/")]
14
  pub async fn index(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
15
- Ok(HttpResponse::Ok().body(
16
- crate::templates::views::index::index(
17
- &config.style.colorscheme,
18
- &config.style.theme,
19
- &config.style.animation,
20
- )
21
- .0,
22
- ))
 
 
23
  }
24
 
25
  /// Handles the route of any other accessed route/page which is not provided by the
@@ -52,14 +54,16 @@ pub async fn robots_data(_req: HttpRequest) -> Result<HttpResponse, Box<dyn std:
52
  /// Handles the route of about page of the `websurfx` meta search engine website.
53
  #[get("/about")]
54
  pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
55
- Ok(HttpResponse::Ok().body(
56
- crate::templates::views::about::about(
57
- &config.style.colorscheme,
58
- &config.style.theme,
59
- &config.style.animation,
60
- )
61
- .0,
62
- ))
 
 
63
  }
64
 
65
  /// Handles the route of settings page of the `websurfx` meta search engine website.
@@ -67,16 +71,18 @@ pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn st
67
  pub async fn settings(
68
  config: web::Data<Config>,
69
  ) -> Result<HttpResponse, Box<dyn std::error::Error>> {
70
- Ok(HttpResponse::Ok().body(
71
- crate::templates::views::settings::settings(
72
- &config.style.colorscheme,
73
- &config.style.theme,
74
- &config.style.animation,
75
- &config
76
- .upstream_search_engines
77
- .keys()
78
- .collect::<Vec<&String>>(),
79
- )?
80
- .0,
81
- ))
 
 
82
  }
 
12
  /// Handles the route of index page or main page of the `websurfx` meta search engine website.
13
  #[get("/")]
14
  pub async fn index(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
15
+ Ok(HttpResponse::Ok()
16
+ .content_type("text/html; charset=utf-8")
17
+ .body(
18
+ crate::templates::views::index::index(
19
+ &config.style.colorscheme,
20
+ &config.style.theme,
21
+ &config.style.animation,
22
+ )
23
+ .0,
24
+ ))
25
  }
26
 
27
  /// Handles the route of any other accessed route/page which is not provided by the
 
54
  /// Handles the route of about page of the `websurfx` meta search engine website.
55
  #[get("/about")]
56
  pub async fn about(config: web::Data<Config>) -> Result<HttpResponse, Box<dyn std::error::Error>> {
57
+ Ok(HttpResponse::Ok()
58
+ .content_type("text/html; charset=utf-8")
59
+ .body(
60
+ crate::templates::views::about::about(
61
+ &config.style.colorscheme,
62
+ &config.style.theme,
63
+ &config.style.animation,
64
+ )
65
+ .0,
66
+ ))
67
  }
68
 
69
  /// Handles the route of settings page of the `websurfx` meta search engine website.
 
71
  pub async fn settings(
72
  config: web::Data<Config>,
73
  ) -> Result<HttpResponse, Box<dyn std::error::Error>> {
74
+ Ok(HttpResponse::Ok()
75
+ .content_type("text/html; charset=utf-8")
76
+ .body(
77
+ crate::templates::views::settings::settings(
78
+ &config.style.colorscheme,
79
+ &config.style.theme,
80
+ &config.style.animation,
81
+ &config
82
+ .upstream_search_engines
83
+ .keys()
84
+ .collect::<Vec<&String>>(),
85
+ )?
86
+ .0,
87
+ ))
88
  }