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?
|
Looks fiddly, just flagging up that I'd also like to be involved in any review on this. 😇 |
|
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 |
| 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