Skip to content

Commit

Permalink
Handle prometheus post query cache correctly (#590)
Browse files Browse the repository at this point in the history
* 1. Handle prometheus post query cache correctly
2. Support request content type is application JSON with charset

Signed-off-by: xiaoqing <xiaoqingnb@gmail.com>

* fix compile issues

Signed-off-by: James Ranson <james@ranson.org>

* fix typo

Signed-off-by: James Ranson <james@ranson.org>

---------

Signed-off-by: xiaoqing <xiaoqingnb@gmail.com>
Signed-off-by: James Ranson <james@ranson.org>
Co-authored-by: James Ranson <james@ranson.org>
  • Loading branch information
wu0407 and jranson authored Dec 3, 2023
1 parent 3ad1b12 commit fef86de
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 3 additions & 3 deletions pkg/proxy/engines/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ func (pr *proxyRequest) DeriveCacheKey(extra string) string {
}

if methods.HasBody(r.Method) && pc.CacheKeyFormFields != nil && len(pc.CacheKeyFormFields) > 0 {
ct := r.Header.Get(headers.NameContentType)
ct := strings.ToLower(r.Header.Get(headers.NameContentType))
if ct == headers.ValueXFormURLEncoded ||
strings.HasPrefix(ct, headers.ValueMultipartFormData) || ct == headers.ValueApplicationJSON {
strings.HasPrefix(ct, headers.ValueMultipartFormData) || strings.HasPrefix(ct, headers.ValueApplicationJSON) {
if strings.HasPrefix(ct, headers.ValueMultipartFormData) {
pr.ParseMultipartForm(1024 * 1024)
} else if ct == headers.ValueApplicationJSON {
} else if strings.HasPrefix(ct, headers.ValueApplicationJSON) {
var document map[string]interface{}
err := json.Unmarshal(b, &document)
if err == nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/proxy/params/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func GetRequestValues(r *http.Request) (url.Values, string, bool) {
r.Body.Close()
r.Body = io.NopCloser(bytes.NewReader(b))
s = string(b)
isBody = true
if strings.HasPrefix(strings.ToLower(r.Header.Get(headers.NameContentType)), headers.ValueApplicationJSON) {
return v, s, isBody
}
if vs, err := url.ParseQuery(s); err == nil && isQueryBody(r) {
for vsk := range vs {
for _, vsv := range vs[vsk] {
Expand All @@ -108,7 +112,6 @@ func GetRequestValues(r *http.Request) (url.Values, string, bool) {
}
}
}
isBody = true
}
return v, s, isBody
}
Expand Down

0 comments on commit fef86de

Please sign in to comment.