-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for http.MaxBytesHandler #355
Conversation
The `ReadMaxBytes` option is nice, but we should also return properly-coded errors when `net/http.MaxBytesHandler` middleware is in play. This has no API surface area, but it's a nice improvement.
@robbertvanginkel I think this came up early in our discussion of the separation of concerns between |
|
||
func asMaxBytesError(situation string, err error) *Error { | ||
const expect = "http: request body too large" | ||
text := err.Error() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any benefit to using errors.Is here instead or will we never expect it to be wrapped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use errors.Is
on Go 1.18 - the http.MaxByteError
type was introduced in Go 1.19. On 1.18, we should be okay because wrapping will still leave some extra context: http: request body too large
as the error string, which we should detect down below.
I don't know what I was thinking here.
The
ReadMaxBytes
option is nice, but we should also returnproperly-coded errors when
net/http.MaxBytesHandler
middleware is inplay. This has no API surface area, but it's a nice improvement.