httpfs: limit body size

Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
Nicola Murino
2023-10-07 11:28:16 +02:00
parent 64c7588a44
commit 19a95d8c55
2 changed files with 36 additions and 8 deletions

View File

@@ -232,9 +232,13 @@ func (n *Node) SendGetRequest(username, role, relativeURL string, responseHolder
if resp.StatusCode < http.StatusOK || resp.StatusCode > http.StatusNoContent {
return fmt.Errorf("unexpected status code: %d", resp.StatusCode)
}
err = json.NewDecoder(resp.Body).Decode(responseHolder)
respBody, err := io.ReadAll(io.LimitReader(resp.Body, 10485760))
if err != nil {
return fmt.Errorf("unable to decode response as json")
return fmt.Errorf("unable to read response body: %w", err)
}
err = json.Unmarshal(respBody, responseHolder)
if err != nil {
return errors.New("unable to decode response as json")
}
return nil
}