Uh oh!
There was an error while loading. Please reload this page.
Fix Content-Lenght calculation of unicode string - #1484
Conversation
florimondmanca
left a comment
There was a problem hiding this comment.
Looking very nice, just a few suggestions to make this tighter?
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
lovelydinosaur
commented
Mar 12, 2021
Looks fiddly, just flagging up that I'd also like to be involved in any review on this. 😇 |
lovelydinosaur
commented
Mar 24, 2021
Great, thanks for this, good work! I'd like to see the change footprint reduced on it slightly. I don't think we really need to change |
Uh oh!
There was an error while loading. Please reload this page.
| self.name = name | ||
| fileobj: FileContent | ||
There was a problem hiding this comment.
I'd suggest we don't change this.
| # mismatch due to str -> bytes encoding. | ||
| # See: https://github.com/encode/httpx/issues/1482 | ||
| fileobj = to_bytes(fileobj) | ||
| def get_length(self) -> int: | ||
| headers = self.render_headers() | ||
| if isinstance(self.file, (str, bytes)): |
There was a problem hiding this comment.
The low-footprint change here is presumably to keep this check the same, but use the following...
return len(headers) + len(to_bytes(self.file))
Right?
| def render_data(self) -> typing.Iterator[bytes]: | ||
| if isinstance(self.file, (str, bytes)): | ||
| yield to_bytes(self.file) |
There was a problem hiding this comment.
We shouldn't need to change this.
Fixes #1482