Auto-detect HTML responses in http_serve, serve with text/html content type

This commit is contained in:
Will Anderson
2026-04-29 16:59:59 -05:00
parent ac1f1b895f
commit cd2bc4e84c
+5 -1
View File
@@ -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);