-
-
Notifications
You must be signed in to change notification settings - Fork 857
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
detect length of file-like object? #1490
Comments
Okay, so it looks to me like there's a more sensible behaviour that we could be using for binary data, where we attempt to peek the file(like) length, in the same way that we currently do for multipart data. Currently we're always treating binary data as having an unknown length, and using chunked encoding for it... Lines 77 to 103 in 24a55d7
We probably ought to instead be attempting to use our Line 347 in 24a55d7
|
@tomchristie, thanks. I'll try to come up with a PR. I just wanted to hear if that was a good idea that |
Okay, I think there's two distinctly separate PRs for us to tackle here... Firstly, a bit of refactoring so that Lines 94 to 100 in 24a55d7
Then once that pull request is done, we can follow up with a pull request using One other thing we'll want to be careful about here is what behaviour we end up with if files opened in text mode are used. There's a note in requests about disallowing these in the future. (Which makes sense for us) |
Thanks, @tomchristie for the fix. I have been meaning to contribute, but life got in the way. 🙂 |
Checklist
Is your feature related to a problem? Please describe.
I'm using
httpx
to upload files to a WebDAV server, which usesPUT
. The problem here is that not a lot of server has chunked uploading support for PUT.When uploading a file-like object,
request
tries to detect file size to send it inContent-Length
header usingsuper_len()
. Buthttpx
usesTransfer-Encoding: chunked
. So, the files end up empty or the server throws a411 Length Required
response.The difference in behaviour with respect to
requests
can be demonstrated as follows:Describe the solution you would like.
It'd be great to have the same behaviour as
requests
here, i.e. trying to detect the size and then falling back to chunked encoding.Describe alternatives you considered
As a workaround, I can use
peek_filelike_length
and a custom headerContent-Length
which is respected, that works well for me.Additional context
We had a long discussion in iterative/dvc#4796 regarding it.
nextcloud-snap
that I use locally for testing, does not have support this either due to a bug in Apache (or, some modules in it): nextcloud-snap/nextcloud-snap#365.And, Sabredav (
owncloud
/nextcloud
uses them internally) wiki has a good insight on this (though the article is >6 years old):Note that the recent servers do support chunked encoding, but we still find a lot of old servers or are using certain modules that are buggy wrt chunked encoding.
I understand that it's the server that is not http/1.1 compliant. And, if
httpx
does not want to support, I'm okay with the workaround as well. But I'd happy to make a PR if we decide to do so. Thanks. 🙂The text was updated successfully, but these errors were encountered: