Skip to content

Commit

Permalink
supply correct headers for remote browsers to render correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fxgst committed Jan 22, 2024
1 parent d0b4ccd commit e68bfc6
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions tools/ui/src/didjs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,17 @@ fn subtype(new: String, old: String) -> Result<(), String> {
subtype::subtype(&mut gamma, &new_env, &new_actor, &old_actor).map_err(|e| e.to_string())
}

fn retrieve(path: &str) -> Option<&'static [u8]> {
fn retrieve(path: &str) -> Option<(&str, &'static [u8])> {
match path {
"/index.html" | "/" => Some(include_bytes!("../../dist/didjs/index.html")),
"/favicon.ico" => Some(include_bytes!("../../dist/didjs/favicon.ico")),
"/index.js" => Some(include_bytes!("../../dist/didjs/index.js")),
"/index.html" | "/" => Some(("text/html", include_bytes!("../../dist/didjs/index.html"))),
"/favicon.ico" => Some((
"image/x-icon",
include_bytes!("../../dist/didjs/favicon.ico"),
)),
"/index.js" => Some((
"application/javascript",
include_bytes!("../../dist/didjs/index.js"),
)),
_ => None,
}
}
Expand All @@ -91,11 +97,11 @@ fn get_path(url: &str) -> Option<&str> {
fn http_request(request: HttpRequest) -> HttpResponse {
//TODO add /canister_id/ as endpoint when ICQC is available.
let path = get_path(request.url.as_str()).unwrap_or("/");
if let Some(bytes) = retrieve(path) {
if let Some((content_type, bytes)) = retrieve(path) {
HttpResponse {
status_code: 200,
headers: vec![
//HeaderField("Content-Encoding".to_string(), "gzip".to_string()),
HeaderField("Content-Type".to_string(), content_type.to_string()),
HeaderField("Content-Length".to_string(), format!("{}", bytes.len())),
HeaderField("Cache-Control".to_string(), format!("max-age={}", 600)),
],
Expand Down

0 comments on commit e68bfc6

Please sign in to comment.