MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / ValidateQuery

Function ValidateQuery

internal/server/middleware_request_text.go:269–287  ·  view source on GitHub ↗

ValidateQuery is the query-string half of the same rule ValidatePath applies to the path: reject a request whose DECODED query keys or values are not values the database can be asked about. WHY A TRANSPORT RULE HERE, when BUG-2782 said the query string would be validated at its points of use. That

(decorate func(http.Handler) http.Handler)

Source from the content-addressed store, hash-verified

267//
268// BUG-2784.
269func ValidateQuery(decorate func(http.Handler) http.Handler) func(http.Handler) http.Handler {
270 var reject http.Handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
271 w.Header().Set("Content-Type", "application/json")
272 writeError(w, http.StatusBadRequest, "invalid_query",
273 "Request query string contains invalid UTF-8 or a NUL byte")
274 })
275 if decorate != nil {
276 reject = decorate(reject)
277 }
278 return func(next http.Handler) http.Handler {
279 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
280 if !validQueryText(r.URL.RawQuery) {
281 reject.ServeHTTP(w, r)
282 return
283 }
284 next.ServeHTTP(w, r)
285 })
286 }
287}
288
289// validQueryText reports whether every key and value a handler could read
290// out of this raw query string is bindableText.

Callers 1

setupRouterMethod · 0.85

Calls 5

writeErrorFunction · 0.85
validQueryTextFunction · 0.85
SetMethod · 0.45
HeaderMethod · 0.45
ServeHTTPMethod · 0.45

Tested by

no test coverage detected