Skip to content

Commit cf7e1a0

Browse files
authored
Merge pull request #2479 from keboola/JakubK-AJDA-1935
Data Apps - Inactivity Timeout
2 parents e1b5e86 + 0598048 commit cf7e1a0

3 files changed

Lines changed: 55 additions & 0 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,19 @@ 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+
// WORKAROUND for AJDA-1935: Return plain text for Streamlit health checks.
66+
// Streamlit displays error responses in a modal that doesn't properly render HTML,
67+
// resulting in broken/escaped HTML being shown to users. This returns plain text
68+
// for known Streamlit internal endpoints to provide a better user experience.
69+
// See IsStreamlitHealthCheck() for full documentation and limitations.
70+
if IsStreamlitHealthCheck(req.URL.Path) {
71+
plainText := renderPlainText(page, status)
72+
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
73+
w.WriteHeader(status)
74+
_, _ = w.Write([]byte(plainText))
75+
return
76+
}
77+
6578
var buf bytes.Buffer
6679

6780
// Render template
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package pagewriter
2+
3+
import "strings"
4+
5+
// IsStreamlitHealthCheck detects Streamlit health check endpoints.
6+
//
7+
// WORKAROUND: This is a temporary solution for AJDA-1935 to prevent broken HTML
8+
// from being displayed in Streamlit's error modal when the app is starting or unavailable.
9+
// Streamlit makes health check requests to these endpoints and renders the response
10+
// in an error dialog, which doesn't properly handle HTML responses.
11+
//
12+
// Limitations:
13+
// - This approach is Streamlit-specific and does not scale to other frameworks
14+
// - Only covers /_stcore/health and /_stcore/host-config endpoints
15+
// - Other Streamlit internal endpoints (e.g., /_stcore/stream) are not covered
16+
//
17+
// Long-term solution: Modify Streamlit to properly handle HTML error responses
18+
// or provide a query parameter for clients to request plain text format.
19+
func IsStreamlitHealthCheck(path string) bool {
20+
return strings.HasSuffix(path, "/_stcore/health") || strings.HasSuffix(path, "/_stcore/host-config")
21+
}
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)