Skip to content

Commit aaae466

Browse files
committed
support both get and post requests
1 parent ccba226 commit aaae466

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

query-proxy/internal/app/query-proxy/reverse.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,22 @@ func modifyRequest(r *http.Request, prometheusServerURL *url.URL, prometheusQuer
4141
return err
4242
}
4343

44-
form := r.Form
45-
form.Set(prometheusQueryParameter, expr.String())
46-
body := form.Encode()
47-
r.Body = io.NopCloser(strings.NewReader(body))
48-
r.ContentLength = int64(len(body))
49-
r.URL.RawQuery = ""
50-
r.URL.Fragment = ""
51-
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
52-
53-
log.Println("TRANSFORMED TO ", body)
44+
if r.Method == "GET" {
45+
q := r.URL.Query()
46+
q.Set(prometheusQueryParameter, expr.String())
47+
r.URL.RawQuery = q.Encode()
48+
log.Println("TRANSFORMED QUERY TO", r.URL)
49+
} else {
50+
form := r.Form
51+
form.Set(prometheusQueryParameter, expr.String())
52+
body := form.Encode()
53+
r.Body = io.NopCloser(strings.NewReader(body))
54+
r.ContentLength = int64(len(body))
55+
r.URL.RawQuery = ""
56+
r.URL.Fragment = ""
57+
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
58+
log.Println("TRANSFORMED BODY TO", body)
59+
}
5460

5561
return nil
5662
}

0 commit comments

Comments
 (0)