Skip to content

Commit

Permalink
fix the behavior of empty values
Browse files Browse the repository at this point in the history
Signed-off-by: h-otter <[email protected]>
  • Loading branch information
h-otter committed Oct 29, 2023
1 parent aced907 commit 6e70621
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions injectproxy/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,13 @@ func (r *routes) matcher(w http.ResponseWriter, req *http.Request) {
Value: labelValuesToRegexpString(MustLabelValues(req.Context())),
}

var q url.Values
if req.Method == http.MethodPost && req.Header.Get("Content-Type") == "application/x-www-form-urlencoded" {
q := req.URL.Query()
if err := injectMatcher(q, matcher); err != nil {
return
}

req.URL.RawQuery = q.Encode()
if req.Method == http.MethodPost {
if err := req.ParseForm(); err != nil {
return
}
Expand All @@ -555,18 +560,16 @@ func (r *routes) matcher(w http.ResponseWriter, req *http.Request) {
newBody := q.Encode()
req.Body = io.NopCloser(strings.NewReader(newBody))
req.ContentLength = int64(len(newBody))
} else {
q = req.URL.Query()
if err := injectMatcher(q, matcher); err != nil {
return
}
}

req.URL.RawQuery = q.Encode()
r.handler.ServeHTTP(w, req)
}

func injectMatcher(q url.Values, matcher *labels.Matcher) error {
if len(q) == 0 {
return nil
}

matchers := q[matchersParam]
if len(matchers) == 0 {
q.Set(matchersParam, matchersToString(matcher))
Expand Down

0 comments on commit 6e70621

Please sign in to comment.