Return ErrResponseTooLarge instead of truncating response body
WithMaxResponseBody wrapped the body in io.LimitedReader, which returns EOF at the cap, so Bytes/JSON/XML silently returned a truncated body with a nil error despite the documented contract. Read one byte past the limit and return the new ErrResponseTooLarge sentinel when exceeded; bodies exactly at the limit still succeed.
This commit is contained in:
6
error.go
6
error.go
@@ -1,6 +1,7 @@
|
||||
package httpx
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
@@ -18,6 +19,11 @@ var (
|
||||
ErrNoHealthy = balancer.ErrNoHealthy
|
||||
)
|
||||
|
||||
// ErrResponseTooLarge is returned when reading a response body that exceeds
|
||||
// the limit configured via WithMaxResponseBody. Any bytes read up to the
|
||||
// limit are returned alongside the error.
|
||||
var ErrResponseTooLarge = errors.New("httpx: response body exceeds configured limit")
|
||||
|
||||
// Error provides structured error information for failed HTTP operations.
|
||||
type Error struct {
|
||||
// Op is the operation that failed (e.g. "Get", "Do").
|
||||
|
||||
Reference in New Issue
Block a user