Skip to content

Commit 0b81245

Browse files
natocTohosekpeter
authored andcommitted
feat: add support for plain text response
1 parent cfc0161 commit 0b81245

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

internal/pkg/service/appsproxy/proxy/pagewriter/pagewriter.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ func (pw *Writer) MountAssets(mux *http.ServeMux) {
6262
}
6363

6464
func (pw *Writer) writePage(w http.ResponseWriter, req *http.Request, page string, status int, data any) {
65+
// Streamlit health checks expect plain text responses, not HTML
66+
if IsStreamlitHealthCheck(req.URL.Path) {
67+
plainText := renderPlainText(page, status)
68+
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
69+
w.WriteHeader(status)
70+
_, _ = w.Write([]byte(plainText))
71+
return
72+
}
73+
6574
var buf bytes.Buffer
6675

6776
// Render template
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package pagewriter
2+
3+
import "strings"
4+
5+
func IsStreamlitHealthCheck(path string) bool {
6+
return strings.HasSuffix(path, "/_stcore/health") || strings.HasSuffix(path, "/_stcore/host-config")
7+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package pagewriter
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
func renderPlainText(page string, status int) string {
8+
switch page {
9+
case "spinner.gohtml":
10+
return `The application is re-starting. Please wait...`
11+
12+
case "restart_disabled.gohtml":
13+
return `The application has been stopped and cannot be restarted automatically.`
14+
15+
case "error.gohtml":
16+
return fmt.Sprintf("An error occurred (status code: %d). Please try again later.", status)
17+
18+
default:
19+
return `No additional information is available.`
20+
}
21+
}

0 commit comments

Comments
 (0)