Skip to content

Commit 6e70621

Browse files
committed
fix the behavior of empty values
Signed-off-by: h-otter <[email protected]>
1 parent aced907 commit 6e70621

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Diff for: injectproxy/routes.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,13 @@ func (r *routes) matcher(w http.ResponseWriter, req *http.Request) {
539539
Value: labelValuesToRegexpString(MustLabelValues(req.Context())),
540540
}
541541

542-
var q url.Values
543-
if req.Method == http.MethodPost && req.Header.Get("Content-Type") == "application/x-www-form-urlencoded" {
542+
q := req.URL.Query()
543+
if err := injectMatcher(q, matcher); err != nil {
544+
return
545+
}
546+
547+
req.URL.RawQuery = q.Encode()
548+
if req.Method == http.MethodPost {
544549
if err := req.ParseForm(); err != nil {
545550
return
546551
}
@@ -555,18 +560,16 @@ func (r *routes) matcher(w http.ResponseWriter, req *http.Request) {
555560
newBody := q.Encode()
556561
req.Body = io.NopCloser(strings.NewReader(newBody))
557562
req.ContentLength = int64(len(newBody))
558-
} else {
559-
q = req.URL.Query()
560-
if err := injectMatcher(q, matcher); err != nil {
561-
return
562-
}
563563
}
564564

565-
req.URL.RawQuery = q.Encode()
566565
r.handler.ServeHTTP(w, req)
567566
}
568567

569568
func injectMatcher(q url.Values, matcher *labels.Matcher) error {
569+
if len(q) == 0 {
570+
return nil
571+
}
572+
570573
matchers := q[matchersParam]
571574
if len(matchers) == 0 {
572575
q.Set(matchersParam, matchersToString(matcher))

0 commit comments

Comments
 (0)