Skip to content

Commit

Permalink
support both get and post requests
Browse files Browse the repository at this point in the history
  • Loading branch information
ikethecoder committed Nov 24, 2023
1 parent ccba226 commit aaae466
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions query-proxy/internal/app/query-proxy/reverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,22 @@ func modifyRequest(r *http.Request, prometheusServerURL *url.URL, prometheusQuer
return err
}

form := r.Form
form.Set(prometheusQueryParameter, expr.String())
body := form.Encode()
r.Body = io.NopCloser(strings.NewReader(body))
r.ContentLength = int64(len(body))
r.URL.RawQuery = ""
r.URL.Fragment = ""
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")

log.Println("TRANSFORMED TO ", body)
if r.Method == "GET" {
q := r.URL.Query()
q.Set(prometheusQueryParameter, expr.String())
r.URL.RawQuery = q.Encode()
log.Println("TRANSFORMED QUERY TO", r.URL)
} else {
form := r.Form
form.Set(prometheusQueryParameter, expr.String())
body := form.Encode()
r.Body = io.NopCloser(strings.NewReader(body))
r.ContentLength = int64(len(body))
r.URL.RawQuery = ""
r.URL.Fragment = ""
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
log.Println("TRANSFORMED BODY TO", body)
}

return nil
}
Expand Down

0 comments on commit aaae466

Please sign in to comment.