Fix invalid invocations of errors.LineTooLong.#1335
Conversation
| 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.
bname.decode('utf-8') can fail with own exception
There was a problem hiding this comment.
Can it though? This is caught before by "Invalid Header". Changed it anyhow :)
| if header_length > self.max_field_size: | ||
| raise errors.LineTooLong( | ||
| 'limit request headers fields size') | ||
| 'request header field %s' % bname.decode("utf8"), |
| 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.
this looks inconvenient: LineTooLong above is raised with single argument (formated string) and with two args here
There was a problem hiding this comment.
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".
|
I'll fix the failing tests and add some more. |
1f4d4c7 to
f5cab5b
Compare
|
Thanks! |
What do these changes do?
Fix unhelpful messages on
LineTooLongexceptions 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.txtCHANGES.rst#issue_numberformat at the end of changelog message. Use Pull Request number if there are no issues for PR or PR covers the issue only partially.