Auto-detect HTML responses in http_serve, serve with text/html content type
This commit is contained in:
+5
-1
@@ -3915,9 +3915,13 @@ fn dispatch_builtin(
|
|||||||
method, path, _http_status, _req_latency_ms, request_id
|
method, path, _http_status, _req_latency_ms, request_id
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Auto-detect HTML responses and serve with text/html content type.
|
||||||
|
let trimmed = response_body.trim_start();
|
||||||
|
let is_html = trimmed.starts_with("<!DOCTYPE") || trimmed.starts_with("<html") || trimmed.starts_with("<nav") || trimmed.starts_with("<div") || trimmed.starts_with("<main");
|
||||||
|
let response_header = if is_html { content_html } else { content_json };
|
||||||
let _ = request.respond(
|
let _ = request.respond(
|
||||||
tiny_http::Response::from_string(response_body)
|
tiny_http::Response::from_string(response_body)
|
||||||
.with_header(content_json)
|
.with_header(response_header)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
stack.push(Value::Nil);
|
stack.push(Value::Nil);
|
||||||
|
|||||||
Reference in New Issue
Block a user