Skip to content

Commit

Permalink
fix: allow non-GET requests for paths ending with /stream (#716)
Browse files Browse the repository at this point in the history
## What type of PR is this?

/kind bug

## What this PR does / why we need it:

This PR modifies the ReadOnlyMode middleware to allow non-GET requests
for URLs ending with '/stream'.

Key changes include:
- Adjusting the middleware logic to permit non-GET requests for paths
ending with '/stream'.
- Ensuring streaming endpoints remain functional in read-only mode,
addressing a specific use case where streaming data is required.

## Which issue(s) this PR fixes:

Fixes #
  • Loading branch information
elliotxx authored Jan 13, 2025
1 parent c643743 commit 28ee157
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/core/middleware/readonly.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ package middleware

import (
"net/http"
"strings"
)

// ReadOnlyMode disallows non-GET requests in read-only mode.
func ReadOnlyMode(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
if r.Method != http.MethodGet && !strings.HasSuffix(r.URL.Path, "/stream") {
http.Error(w, "The server is currently in read-only mode.", http.StatusMethodNotAllowed)
return
}
Expand Down

0 comments on commit 28ee157

Please sign in to comment.