From 022f1c1d9f44c1606c9be556cf36e649c8879b99 Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Thu, 20 Nov 2025 17:38:48 +0100 Subject: [PATCH 1/4] fix: handler HEAD calls in sse routes --- internal/api/handlers/app_logs.go | 6 ++++++ internal/api/handlers/app_status.go | 6 ++++++ internal/api/handlers/system_resources.go | 11 ++++++++--- internal/api/handlers/update.go | 6 ++++++ 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/internal/api/handlers/app_logs.go b/internal/api/handlers/app_logs.go index 2cf44c87..398a4bf5 100644 --- a/internal/api/handlers/app_logs.go +++ b/internal/api/handlers/app_logs.go @@ -80,6 +80,12 @@ func HandleAppLogs( Follow: follow, } + // Handle HEAD requests with erly return + if r.Method == http.MethodHead { + render.EncodeResponse(w, http.StatusOK, nil) + return + } + sseStream, err := render.NewSSEStream(r.Context(), w) if err != nil { slog.Error("Unable to create SSE stream", slog.String("error", err.Error())) diff --git a/internal/api/handlers/app_status.go b/internal/api/handlers/app_status.go index 89a82e41..5a97d496 100644 --- a/internal/api/handlers/app_status.go +++ b/internal/api/handlers/app_status.go @@ -34,6 +34,12 @@ func HandlerAppStatus( cfg config.Configuration, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + // Handle HEAD requests with erly return + if r.Method == http.MethodHead { + render.EncodeResponse(w, http.StatusOK, nil) + return + } + sseStream, err := render.NewSSEStream(r.Context(), w) if err != nil { slog.Error("Unable to create SSE stream", slog.String("error", err.Error())) diff --git a/internal/api/handlers/system_resources.go b/internal/api/handlers/system_resources.go index dc746409..21baac19 100644 --- a/internal/api/handlers/system_resources.go +++ b/internal/api/handlers/system_resources.go @@ -26,8 +26,13 @@ import ( func HandleSystemResources() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - ctx := r.Context() - sseStream, err := render.NewSSEStream(ctx, w) + // Handle HEAD requests with erly return + if r.Method == http.MethodHead { + render.EncodeResponse(w, http.StatusOK, nil) + return + } + + sseStream, err := render.NewSSEStream(r.Context(), w) if err != nil { slog.Error("Unable to create SSE stream", slog.String("error", err.Error())) render.EncodeResponse(w, http.StatusInternalServerError, models.ErrorResponse{Details: "unable to create SSE stream"}) @@ -35,7 +40,7 @@ func HandleSystemResources() http.HandlerFunc { } defer sseStream.Close() - resources, err := orchestrator.SystemResources(ctx, nil) + resources, err := orchestrator.SystemResources(r.Context(), nil) if err != nil { sseStream.SendError(render.SSEErrorData{ Code: render.InternalServiceErr, diff --git a/internal/api/handlers/update.go b/internal/api/handlers/update.go index 839fdcf5..2c2c2f29 100644 --- a/internal/api/handlers/update.go +++ b/internal/api/handlers/update.go @@ -127,6 +127,12 @@ func HandleUpdateApply(updater *update.Manager) http.HandlerFunc { func HandleUpdateEvents(updater *update.Manager) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + // Handle HEAD requests with erly return + if r.Method == http.MethodHead { + render.EncodeResponse(w, http.StatusOK, nil) + return + } + sseStream, err := render.NewSSEStream(r.Context(), w) if err != nil { slog.Error("Unable to create SSE stream", slog.String("error", err.Error())) From 5c25409e51d124b22b51efafaac31ffa309b2053 Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Fri, 21 Nov 2025 10:22:18 +0100 Subject: [PATCH 2/4] fix typo --- internal/api/handlers/app_logs.go | 2 +- internal/api/handlers/app_status.go | 2 +- internal/api/handlers/system_resources.go | 2 +- internal/api/handlers/update.go | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/api/handlers/app_logs.go b/internal/api/handlers/app_logs.go index 398a4bf5..3acbee9a 100644 --- a/internal/api/handlers/app_logs.go +++ b/internal/api/handlers/app_logs.go @@ -80,7 +80,7 @@ func HandleAppLogs( Follow: follow, } - // Handle HEAD requests with erly return + // Handle HEAD requests with early return if r.Method == http.MethodHead { render.EncodeResponse(w, http.StatusOK, nil) return diff --git a/internal/api/handlers/app_status.go b/internal/api/handlers/app_status.go index 5a97d496..722b0e02 100644 --- a/internal/api/handlers/app_status.go +++ b/internal/api/handlers/app_status.go @@ -34,7 +34,7 @@ func HandlerAppStatus( cfg config.Configuration, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - // Handle HEAD requests with erly return + // Handle HEAD requests with early return if r.Method == http.MethodHead { render.EncodeResponse(w, http.StatusOK, nil) return diff --git a/internal/api/handlers/system_resources.go b/internal/api/handlers/system_resources.go index 21baac19..e1962d67 100644 --- a/internal/api/handlers/system_resources.go +++ b/internal/api/handlers/system_resources.go @@ -26,7 +26,7 @@ import ( func HandleSystemResources() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - // Handle HEAD requests with erly return + // Handle HEAD requests with early return if r.Method == http.MethodHead { render.EncodeResponse(w, http.StatusOK, nil) return diff --git a/internal/api/handlers/update.go b/internal/api/handlers/update.go index 2c2c2f29..0f49757a 100644 --- a/internal/api/handlers/update.go +++ b/internal/api/handlers/update.go @@ -127,7 +127,7 @@ func HandleUpdateApply(updater *update.Manager) http.HandlerFunc { func HandleUpdateEvents(updater *update.Manager) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - // Handle HEAD requests with erly return + // Handle HEAD requests with early return if r.Method == http.MethodHead { render.EncodeResponse(w, http.StatusOK, nil) return From 0f9969c3bc141f7b87ea1a4116b3d994889b4e60 Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Fri, 21 Nov 2025 17:13:09 +0100 Subject: [PATCH 3/4] make hotfix instead --- internal/api/handlers/update.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/internal/api/handlers/update.go b/internal/api/handlers/update.go index 0f49757a..49ec1b29 100644 --- a/internal/api/handlers/update.go +++ b/internal/api/handlers/update.go @@ -127,7 +127,8 @@ func HandleUpdateApply(updater *update.Manager) http.HandlerFunc { func HandleUpdateEvents(updater *update.Manager) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - // Handle HEAD requests with early return + // HOTFIX: app-lab use HEAD requests to check endpoint availability + // so we need to handle them here by early return without opening SSE stream if r.Method == http.MethodHead { render.EncodeResponse(w, http.StatusOK, nil) return From 2b5fe26e63e1ef64f39daa39b088eae58a804800 Mon Sep 17 00:00:00 2001 From: lucarin91 Date: Fri, 21 Nov 2025 17:16:33 +0100 Subject: [PATCH 4/4] revert other sse endpoints --- internal/api/handlers/app_logs.go | 6 ------ internal/api/handlers/app_status.go | 6 ------ internal/api/handlers/system_resources.go | 11 +++-------- 3 files changed, 3 insertions(+), 20 deletions(-) diff --git a/internal/api/handlers/app_logs.go b/internal/api/handlers/app_logs.go index 3acbee9a..2cf44c87 100644 --- a/internal/api/handlers/app_logs.go +++ b/internal/api/handlers/app_logs.go @@ -80,12 +80,6 @@ func HandleAppLogs( Follow: follow, } - // Handle HEAD requests with early return - if r.Method == http.MethodHead { - render.EncodeResponse(w, http.StatusOK, nil) - return - } - sseStream, err := render.NewSSEStream(r.Context(), w) if err != nil { slog.Error("Unable to create SSE stream", slog.String("error", err.Error())) diff --git a/internal/api/handlers/app_status.go b/internal/api/handlers/app_status.go index 722b0e02..89a82e41 100644 --- a/internal/api/handlers/app_status.go +++ b/internal/api/handlers/app_status.go @@ -34,12 +34,6 @@ func HandlerAppStatus( cfg config.Configuration, ) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - // Handle HEAD requests with early return - if r.Method == http.MethodHead { - render.EncodeResponse(w, http.StatusOK, nil) - return - } - sseStream, err := render.NewSSEStream(r.Context(), w) if err != nil { slog.Error("Unable to create SSE stream", slog.String("error", err.Error())) diff --git a/internal/api/handlers/system_resources.go b/internal/api/handlers/system_resources.go index e1962d67..dc746409 100644 --- a/internal/api/handlers/system_resources.go +++ b/internal/api/handlers/system_resources.go @@ -26,13 +26,8 @@ import ( func HandleSystemResources() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { - // Handle HEAD requests with early return - if r.Method == http.MethodHead { - render.EncodeResponse(w, http.StatusOK, nil) - return - } - - sseStream, err := render.NewSSEStream(r.Context(), w) + ctx := r.Context() + sseStream, err := render.NewSSEStream(ctx, w) if err != nil { slog.Error("Unable to create SSE stream", slog.String("error", err.Error())) render.EncodeResponse(w, http.StatusInternalServerError, models.ErrorResponse{Details: "unable to create SSE stream"}) @@ -40,7 +35,7 @@ func HandleSystemResources() http.HandlerFunc { } defer sseStream.Close() - resources, err := orchestrator.SystemResources(r.Context(), nil) + resources, err := orchestrator.SystemResources(ctx, nil) if err != nil { sseStream.SendError(render.SSEErrorData{ Code: render.InternalServiceErr,