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

Chore: Update max bytes reader middleware error message #1072

Merged
merged 3 commits into from
Sep 8, 2024

Conversation

itsmylife
Copy link
Contributor

What this PR does / why we need it:

We return the remaining bytes that need to be read when we hit the limit in the error message. That is confusing and misleading. Here I am making the change to return the actual response limit value when we hit the limit.

Also, I did some small tweaks in test files to make it more understandable.

Comment on lines +16 to +17
expectedBodyLength int
expectedBody string
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Helps me to create a mental model when I read the tests

require.Len(t, bodyBytes, tc.bodyLength)
require.Equal(t, string(bodyBytes), tc.body)
require.Len(t, bodyBytes, tc.expectedBodyLength)
require.Equal(t, tc.expectedBody, string(bodyBytes))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced the expected and the actual values so the failed test message can help me with what's expected and what's actual value.

@itsmylife itsmylife marked this pull request as ready for review September 6, 2024 12:35
@itsmylife itsmylife requested a review from a team as a code owner September 6, 2024 12:35
@itsmylife itsmylife requested review from wbrowne, andresmgot, xnyo and marefr and removed request for a team September 6, 2024 12:35
Copy link
Contributor

@marefr marefr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

}

type maxBytesReader struct {
r io.ReadCloser // underlying reader
n int64 // max bytes remaining
a int64 // the actual limit
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit. Naming could be improved for these fields :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marefr An attempt has been made here 6441e0b but I am not sure if those are good enough.

Copy link
Contributor

@andresmgot andresmgot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one minor suggestion.

backend/httpclient/max_bytes_reader.go Outdated Show resolved Hide resolved
@itsmylife itsmylife merged commit 12d6a76 into main Sep 8, 2024
3 checks passed
@itsmylife itsmylife deleted the ismail/update-resp-limit-err-msg branch September 8, 2024 11:20
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