Make route-D the default flat preview engine
POST /preview served the v1 pipeline while route-D lived behind /api/route-d and the project engine switch. Try route_d::preview_json first and keep the v1 compiler as the fallback when route-D rejects the source; ?engine=v1 forces the old path and the project endpoints are unchanged. Both paths now answer with an X-Preview-Engine header (route-d or v1) so the choice is observable, and the server test helper compares header names case-insensitively because tiny-http lowercases them. A server test posts a document and checks route-d by default plus v1 when the query asks for it.
This commit is contained in:
1 parent
621a8abb92
commit
a56d441513
4 files changed
+59
-11
No files matched your search
+24
-3
@@ -26,9 +26,13 @@ impl Response {
|
||||
}
|
||||
|
||||
fn header(&self, name: &str) -> Option<&str> {
|
||||
self.headers
|
||||
.lines()
|
||||
.find_map(|line| line.strip_prefix(&format!("{name}: ")))
|
||||
let needle = format!("{}: ", name.to_ascii_lowercase());
|
||||
self.headers.lines().find_map(|line| {
|
||||
let lowered = line.to_ascii_lowercase();
|
||||
lowered
|
||||
.strip_prefix(&needle)
|
||||
.map(|_| line[needle.len()..].trim())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2299,3 +2303,20 @@ fn project_images_resolve_through_graphicspath() {
|
||||
"pdf should embed the image resolved through graphicspath"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preview_uses_route_d_by_default_and_v1_on_request() {
|
||||
let server = TestServer::start("preview-engine");
|
||||
let source = b"\\documentclass{article}\n\\begin{document}\n\nHello\n\n\\end{document}";
|
||||
let default = server.request("POST", "/preview", source, "text/plain");
|
||||
assert_eq!(default.status, 200, "{}", default.text());
|
||||
assert_eq!(
|
||||
default.header("X-Preview-Engine"),
|
||||
Some("route-d"),
|
||||
"headers: {}",
|
||||
default.headers
|
||||
);
|
||||
let v1 = server.request("POST", "/preview?engine=v1", source, "text/plain");
|
||||
assert_eq!(v1.status, 200, "{}", v1.text());
|
||||
assert_eq!(v1.header("X-Preview-Engine"), Some("v1"));
|
||||
}
|
||||
Reference in new issue
Block a user