-
-
Notifications
You must be signed in to change notification settings - Fork 856
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 Content-Lenght calculation of unicode string #1484
Conversation
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.
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 |
@@ -66,8 +62,6 @@ class FileField: | |||
def __init__(self, name: str, value: FileTypes) -> None: | |||
self.name = name | |||
|
|||
fileobj: FileContent | |||
|
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'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) | ||
|
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.
Or add this.
@@ -87,7 +87,7 @@ def __init__(self, name: str, value: FileTypes) -> None: | |||
def get_length(self) -> int: | |||
headers = self.render_headers() | |||
|
|||
if isinstance(self.file, (str, bytes)): |
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.
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?
@@ -119,8 +119,8 @@ def render_headers(self) -> bytes: | |||
return self._headers | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't need to change this.
Fixes #1482