Pulse/internal/dockeragent/http_limits.go
2026-03-18 16:06:30 +00:00

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
}