2022-10-26 10:54:54 +03:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2022-10-26 14:58:32 +03:00
|
|
|
const MB = 1 << 20
|
|
|
|
|
|
|
|
func buildLimitedRawResponse(resp *http.Response) ([]byte, error) {
|
2022-10-26 10:54:54 +03:00
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2022-10-26 18:07:04 +03:00
|
|
|
limitReader := io.LimitReader(resp.Body, MB)
|
2022-10-26 14:58:32 +03:00
|
|
|
body, err := io.ReadAll(limitReader)
|
|
|
|
|
2022-10-26 10:54:54 +03:00
|
|
|
if err != nil {
|
2022-10-26 14:58:32 +03:00
|
|
|
return body, err
|
2022-10-26 10:54:54 +03:00
|
|
|
}
|
|
|
|
|
2022-10-26 14:58:32 +03:00
|
|
|
return body, nil
|
2022-10-26 10:54:54 +03:00
|
|
|
}
|