1
0
mirror of synced 2024-11-22 04:56:06 +03:00
mg-transport-api-client-go/v1/helpers.go
Ruslan Efanov 8765026f7e fix review
2022-10-26 14:58:32 +03:00

23 lines
339 B
Go

package v1
import (
"io"
"net/http"
)
const MB = 1 << 20
const MaxSizeBody = MB * 0.5
func buildLimitedRawResponse(resp *http.Response) ([]byte, error) {
defer resp.Body.Close()
limitReader := io.LimitReader(resp.Body, MaxSizeBody)
body, err := io.ReadAll(limitReader)
if err != nil {
return body, err
}
return body, nil
}