1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-24 07:49:41 +02:00

fix(docker-proxy): reduce DB writes to optimize the proxy calls EE-5516 (#9148)

This commit is contained in:
andres-portainer 2023-07-05 09:25:05 -03:00 committed by GitHub
parent b37120802e
commit 74515f102d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 61 additions and 73 deletions

View file

@ -49,18 +49,8 @@ func getBody(body io.ReadCloser, contentType string, isGzip bool) (interface{},
defer reader.Close()
bodyBytes, err := io.ReadAll(reader)
if err != nil {
return nil, err
}
err = body.Close()
if err != nil {
return nil, err
}
var data interface{}
err = unmarshal(contentType, bodyBytes, &data)
err := unmarshal(contentType, reader, &data)
if err != nil {
return nil, err
}
@ -85,7 +75,7 @@ func marshal(contentType string, data interface{}) ([]byte, error) {
return nil, fmt.Errorf("content type is not supported for marshaling: %s", contentType)
}
func unmarshal(contentType string, body []byte, returnBody interface{}) error {
func unmarshal(contentType string, body io.Reader, returnBody interface{}) error {
// Note: contentType can look like: "application/json" or "application/json; charset=utf-8"
mediaType, _, err := mime.ParseMediaType(contentType)
if err != nil {
@ -94,9 +84,9 @@ func unmarshal(contentType string, body []byte, returnBody interface{}) error {
switch mediaType {
case "application/yaml":
return yaml.Unmarshal(body, returnBody)
return yaml.NewDecoder(body).Decode(returnBody)
case "application/json", "":
return json.Unmarshal(body, returnBody)
return json.NewDecoder(body).Decode(returnBody)
}
return fmt.Errorf("content type is not supported for unmarshaling: %s", contentType)