@@ -9,8 +9,10 @@ import (
99 "net/http"
1010 "net/url"
1111 "os"
12+ "strings"
1213
1314 "k8s.io/apimachinery/pkg/util/sets"
15+ "k8s.io/klog/v2"
1416
1517 "github.com/operator-framework/operator-controller/internal/catalogd/service"
1618)
@@ -21,10 +23,10 @@ const timeFormat = "Mon, 02 Jan 2006 15:04:05 GMT"
2123
2224// CatalogHandlers handles HTTP requests for catalog content
2325type CatalogHandlers struct {
24- store CatalogStore
25- graphqlSvc service.GraphQLService
26- rootURL * url.URL
27- enableMetas bool
26+ store CatalogStore
27+ graphqlSvc service.GraphQLService
28+ rootURL * url.URL
29+ enableMetas bool
2830}
2931
3032// Index provides methods for looking up catalog content by schema/package/name
@@ -183,7 +185,7 @@ func httpError(w http.ResponseWriter, err error) {
183185 code = http .StatusInternalServerError
184186 }
185187 // Log the actual error for debugging
186- fmt . Printf ( "HTTP Error %d: %v \n " , code , err )
188+ klog . ErrorS ( err , "HTTP error " , " code" , code )
187189 http .Error (w , fmt .Sprintf ("%d %s" , code , http .StatusText (code )), code )
188190}
189191
@@ -206,7 +208,7 @@ func allowedMethodsHandler(next http.Handler, allowedMethods ...string) http.Han
206208 allowedMethodSet := sets .New [string ](allowedMethods ... )
207209 return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
208210 // Allow POST requests only for GraphQL endpoint
209- if r . URL . Path != "" && len ( r . URL . Path ) >= 7 && r . URL . Path [ len (r .URL .Path ) - 7 :] != "graphql" && r .Method == http .MethodPost {
211+ if ! strings . HasSuffix (r .URL .Path , "graphql" ) && r .Method == http .MethodPost {
210212 http .Error (w , http .StatusText (http .StatusMethodNotAllowed ), http .StatusMethodNotAllowed )
211213 return
212214 }
0 commit comments