mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-05-07 00:37:36 +00:00
24 lines
533 B
Go
24 lines
533 B
Go
package dockeragent
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
const (
|
|
maxPulseResponseBodyBytes = 1 * 1024 * 1024
|
|
maxVersionResponseBodyBytes = 64 * 1024
|
|
maxRegistryManifestBodyBytes = 4 * 1024 * 1024
|
|
maxRegistryTokenBodyBytes = 1 * 1024 * 1024
|
|
)
|
|
|
|
func readBodyWithLimit(r io.Reader, maxBytes int64) ([]byte, error) {
|
|
body, err := io.ReadAll(io.LimitReader(r, maxBytes+1))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if int64(len(body)) > maxBytes {
|
|
return nil, fmt.Errorf("response body exceeds %d bytes", maxBytes)
|
|
}
|
|
return body, nil
|
|
}
|