-
Notifications
You must be signed in to change notification settings - Fork 66
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
Conversation
expectedBodyLength int | ||
expectedBody string |
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.
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)) |
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.
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.
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.
LGTM
} | ||
|
||
type maxBytesReader struct { | ||
r io.ReadCloser // underlying reader | ||
n int64 // max bytes remaining | ||
a int64 // the actual limit |
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.
Nit. Naming could be improved for these fields :)
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.
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.
LGTM, just one minor suggestion.
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.