forked from TrueCloudLab/frostfs-s3-gw
[#174] Fix router filter query matching
Signed-off-by: Denis Kirillov <d.kirillov@yadro.com>
This commit is contained in:
parent
6e3595e35b
commit
73ed3f7782
2 changed files with 80 additions and 4 deletions
|
@ -111,6 +111,15 @@ func (hf *HandlerFilters) DefaultHandler(handler http.HandlerFunc) *HandlerFilte
|
|||
}
|
||||
|
||||
func (hf *HandlerFilters) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
if handler := hf.match(r); handler != nil {
|
||||
handler.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
hf.defaultHandler.ServeHTTP(w, r)
|
||||
}
|
||||
|
||||
func (hf *HandlerFilters) match(r *http.Request) http.Handler {
|
||||
LOOP:
|
||||
for _, filter := range hf.filters {
|
||||
for _, header := range filter.headers {
|
||||
|
@ -121,13 +130,12 @@ LOOP:
|
|||
}
|
||||
for _, query := range filter.queries {
|
||||
queryVal := r.URL.Query().Get(query.Key)
|
||||
if !r.URL.Query().Has(query.Key) || queryVal != "" && query.Value != queryVal {
|
||||
if !r.URL.Query().Has(query.Key) || query.Value != "" && query.Value != queryVal {
|
||||
continue LOOP
|
||||
}
|
||||
}
|
||||
filter.h.ServeHTTP(w, r)
|
||||
return
|
||||
return filter.h
|
||||
}
|
||||
|
||||
hf.defaultHandler.ServeHTTP(w, r)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue