Skip to content

Commit b06eb34

Browse files
committed
feat: Inject <head> if configured response is invalid html
1 parent 0c354f5 commit b06eb34

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,15 @@ fn handle_connection(
112112
);
113113
let response = match response {
114114
Some(s) if s.contains("<head>") => s.replace("<head>", &format!("<head>{}", script)),
115-
Some(s) => s.replace("<body>", &format!("<head>{}</head><body>", script)),
115+
Some(s) if s.contains("<body>") => {
116+
s.replace("<body>", &format!("<head>{}</head><body>", script))
117+
}
118+
Some(s) => {
119+
log::warn!(
120+
"`response` does not contain a body or head element. Prepending a head element..."
121+
);
122+
format!("<head>{}</head>{}", script, s)
123+
}
116124
None => format!(
117125
"<html><head>{}</head><body>Please return to the app.</body></html>",
118126
script

0 commit comments

Comments
 (0)