@@ -126,13 +126,14 @@ func classifyOp(h http.HandlerFunc) http.HandlerFunc {
126126func transformRequest (h http.HandlerFunc ) http.HandlerFunc {
127127 return func (w http.ResponseWriter , req * http.Request ) {
128128 ctx := req .Context ()
129- reqACL , err := category .FromContext (ctx )
129+ reqACL , err := acl .FromContext (ctx )
130130 if err != nil {
131131 log .Errorln (logTag , ":" , err )
132132 }
133+ isMsearch := * reqACL == acl .Msearch
134+ isSearch := * reqACL == acl .Search
133135 // transform POST request(search) to GET
134- if * reqACL == category .Search {
135- isMsearch := strings .HasSuffix (req .URL .String (), "/_msearch" )
136+ if isSearch || isMsearch {
136137 // Apply source filters
137138 reqPermission , err := permission .FromContext (ctx )
138139 if err != nil {
@@ -151,8 +152,9 @@ func transformRequest(h http.HandlerFunc) http.HandlerFunc {
151152 sources ["excludes" ] = Excludes
152153 }
153154 _ , isExcludesPresent := sources ["excludes" ]
155+ isEmpty := len (Includes ) == 0 && len (Excludes ) == 0
154156 isDefaultInclude := len (Includes ) > 0 && Includes [0 ] == "*"
155- shouldApplyFilters := ! isDefaultInclude || isExcludesPresent
157+ shouldApplyFilters := ! isEmpty && ( ! isDefaultInclude || isExcludesPresent )
156158 if shouldApplyFilters {
157159 if isMsearch {
158160 // Handle the _msearch requests
@@ -175,7 +177,12 @@ func transformRequest(h http.HandlerFunc) http.HandlerFunc {
175177 return
176178 }
177179 reqBody ["_source" ] = sources
178- raw , _ := json .Marshal (reqBody )
180+ raw , err := json .Marshal (reqBody )
181+ if err != nil {
182+ log .Errorln (logTag , ":" , err )
183+ util .WriteBackError (w , err .Error (), http .StatusInternalServerError )
184+ return
185+ }
179186 modifiedBodyString += string (raw )
180187 } else {
181188 modifiedBodyString += element
0 commit comments