Skip to content
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

Merged
merged 3 commits into from
Sep 3, 2022
Merged

Add support for http.MaxBytesHandler #355

merged 3 commits into from
Sep 3, 2022

Conversation

akshayjshah
Copy link
Member

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.

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.
@akshayjshah akshayjshah requested a review from pkwarren September 1, 2022 23:15
@akshayjshah
Copy link
Member Author

@robbertvanginkel I think this came up early in our discussion of the separation of concerns between net/http middleware and Connect interceptors.


func asMaxBytesError(situation string, err error) *Error {
const expect = "http: request body too large"
text := err.Error()
Copy link
Contributor

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?

Copy link
Member Author

@akshayjshah akshayjshah Sep 2, 2022

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.

@akshayjshah akshayjshah merged commit ffe5175 into main Sep 3, 2022
@akshayjshah akshayjshah deleted the ajs/maxbytes branch September 3, 2022 00:51
akshayjshah added a commit that referenced this pull request Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants