-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix invalid invocations of errors.LineTooLong. #1335
Conversation
@@ -102,7 +102,8 @@ def parse_headers(self, lines): | |||
header_length += len(line) | |||
if header_length > self.max_field_size: | |||
raise errors.LineTooLong( | |||
'limit request headers fields size') | |||
'request header field %s' % bname.decode("utf8"), |
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.
bname.decode('utf-8')
can fail with own exception
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.
Can it though? This is caught before by "Invalid Header". Changed it anyhow :)
@@ -113,7 +114,8 @@ def parse_headers(self, lines): | |||
else: | |||
if header_length > self.max_field_size: | |||
raise errors.LineTooLong( | |||
'limit request headers fields size') | |||
'request header field %s' % bname.decode("utf8"), |
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.
same as above
@@ -173,7 +175,7 @@ def __call__(self, out, buf): | |||
raw_data = yield from buf.readuntil( | |||
b'\r\n\r\n', self.max_headers) | |||
except errors.LineLimitExceededParserError as exc: | |||
raise errors.LineTooLong(exc.limit) from None | |||
raise errors.LineTooLong('request header', exc.limit) from None |
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.
this looks inconvenient: LineTooLong
above is raised with single argument (formated string) and with two args here
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.
It's not, and the call here is wrong. Check out the constructor of LineTooLong
(didn't change that one), it expects a "reason" and a limit that was exceeded. The way this was passed before resulted in a broken error message like "400 got more than Unknown bytes when reading 32768"
when it should have read "400 got more than 32768 when reading request header"
.
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.
true, missed that one.
I'll fix the failing tests and add some more. |
1f4d4c7
to
f5cab5b
Compare
Thanks! |
What do these changes do?
Fix unhelpful messages on
LineTooLong
exceptions due to invalid or incomplete calls to their constructor.Are there changes in behavior for the user?
Only in the message that they see in this case.
Related issue number
Checklist
CONTRIBUTORS.txt
CHANGES.rst
#issue_number
format at the end of changelog message. Use Pull Request number if there are no issues for PR or PR covers the issue only partially.