Skip to content
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

should also look into headers for input_size #167

Merged
merged 6 commits into from
Dec 13, 2021

Conversation

tanmaykm
Copy link
Member

@tanmaykm tanmaykm commented Dec 8, 2021

If no content length is set while uploading some contents, Curl defaults to use chunked transfer encoding. In some cases we want to prevent that because the server may not be supporting chunked transfers (and we already know the size).

With this change, the request method will also look at the headers while determining the input size and if found call set_upload_size as usual. So to switch off chunked transfers, one must also know and set the content length header while invoking download or request methods.

If no content length is set while uploading some contents, Curl defaults to use chunked transfer encoding. In some cases we want to prevent that because the server may not be supporting chunked transfers.

With this change, the request method will also look at the headers while determining the input size and if found call `set_upload_size` as usual. So to switch off chunked transfers, one must also know and set the content length header while invoking `download` or `request` methods.
@codecov
Copy link

codecov bot commented Dec 8, 2021

Codecov Report

Merging #167 (07c28aa) into master (a55825b) will decrease coverage by 0.06%.
The diff coverage is 87.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #167      +/-   ##
==========================================
- Coverage   91.35%   91.29%   -0.07%     
==========================================
  Files           5        5              
  Lines         486      494       +8     
==========================================
+ Hits          444      451       +7     
- Misses         42       43       +1     
Impacted Files Coverage Δ
src/Downloads.jl 83.48% <87.50%> (+0.31%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a55825b...07c28aa. Read the comment docs.

tanmaykm added a commit to JuliaComputing/Azure.jl that referenced this pull request Dec 8, 2021
This is to avoid Downloads.jl from initiating chunked transfer when a file IOStream is supplied to `putBlob`.

In 0.4.0, we have switched to using Downloads.jl as the HTTP client instead of HTTP.jl. This issue happens because Downloads.jl
is not able to determine the content length when an IO instance is provided to upload data from, and switches to using a chunked transfer encoding. And the putBlob Azure API endpoint does not support chunked transfers.

The solution is to not use chunked transfers for putBlob. This PR (JuliaLang/Downloads.jl#167) to Downloads.jl would let it also look into the content-length header that we supply to determine the data size to expect in the IO instance we pass.

But until the Downloads.jl PR is merged (and backported), we need this change in Azure.jl to detect IO handles that point to locally mappable files and supply the correct content length and `IOBuffer` of memory mapped file contents as data to upload instead.

fixes: #25
Copy link
Sponsor Member

@StefanKarpinski StefanKarpinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor tweaks but otherwise looks good to me.

src/Downloads.jl Outdated Show resolved Hide resolved
src/Downloads.jl Outdated
@@ -395,4 +399,13 @@ arg_read_size(io::Base.GenericIOBuffer) = bytesavailable(io)
arg_read_size(::Base.DevNull) = 0
arg_read_size(::Any) = nothing

function content_length(headers)
for kv in headers
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be clearer imo with destructuring into (key, value).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 done in f4cdcb5

src/Downloads.jl Outdated Show resolved Hide resolved
tanmaykm and others added 3 commits December 10, 2021 06:32
Co-authored-by: Stefan Karpinski <stefan@karpinski.org>
Co-authored-by: Stefan Karpinski <stefan@karpinski.org>
src/Downloads.jl Outdated Show resolved Hide resolved
@StefanKarpinski StefanKarpinski merged commit ab628ab into master Dec 13, 2021
@StefanKarpinski StefanKarpinski deleted the tan/chunkedtransfer branch December 13, 2021 16:21
tanmaykm added a commit that referenced this pull request Dec 14, 2021
This adds end-to-end tests for the changes introduced in #167.

Verbose mode is switched off for these tests, but switching it on would show that not setting content-length headers results in chunked transfer encoding while setting it prevents that. Both tests should pass.
StefanKarpinski pushed a commit that referenced this pull request Dec 14, 2021
This adds end-to-end tests for the changes introduced in #167.

Verbose mode is switched off for these tests, but switching it on would show that not setting content-length headers results in chunked transfer encoding while setting it prevents that. Both tests should pass.
StefanKarpinski added a commit that referenced this pull request Dec 15, 2021
debug callbacks and end-to-end tests for #167
ericphanson pushed a commit to ericphanson/Downloads.jl that referenced this pull request Jan 26, 2022
If no content length is set while uploading some contents, Curl defaults to use
chunked transfer encoding. In some cases we want to prevent that because the
server may not support chunked transfers.

With this change, the request method will also look at the headers while
determining the input size and if found call `set_upload_size` as usual. So to
switch off chunked transfers, one must also know and set the content length
header while invoking `download` or `request` methods.
ericphanson pushed a commit to ericphanson/Downloads.jl that referenced this pull request Jan 26, 2022
This adds end-to-end tests for the changes introduced in JuliaLang#167.

Verbose mode is switched off for these tests, but switching it on would show that not setting content-length headers results in chunked transfer encoding while setting it prevents that. Both tests should pass.
ericphanson pushed a commit to ericphanson/Downloads.jl that referenced this pull request Jan 27, 2022
If no content length is set while uploading some contents, Curl defaults to use
chunked transfer encoding. In some cases we want to prevent that because the
server may not support chunked transfers.

With this change, the request method will also look at the headers while
determining the input size and if found call `set_upload_size` as usual. So to
switch off chunked transfers, one must also know and set the content length
header while invoking `download` or `request` methods.

(cherry picked from commit ab628ab)
ericphanson pushed a commit to ericphanson/Downloads.jl that referenced this pull request Jan 27, 2022
This adds end-to-end tests for the changes introduced in JuliaLang#167.

Verbose mode is switched off for these tests, but switching it on would show that not setting content-length headers results in chunked transfer encoding while setting it prevents that. Both tests should pass.

(cherry picked from commit 911368d)
DilumAluthge added a commit that referenced this pull request Mar 3, 2022
* Before building and testing the package, make sure that the UUID has not been edited (#128)

(cherry picked from commit 21843d0)

* CI: Standardize the workflow for testing and changing the UUID (#129)

(cherry picked from commit cd002c3)

* fix #131 and add test (#132)

(cherry picked from commit adbb974)

* Improve inferability of download() (#133)

(cherry picked from commit 848d374)

* fix ci badge (#137)

(cherry picked from commit 3870614)

* Fix a handful of invalidations in expression-checking (#138)

ChainRulesCore defines `==(a, b::AbstractThunk)` and its converse,
and this invalidates a couple of poorly-typed Symbol checks.
This more "SSA-like" way of writing the code is easier to infer.

(cherry picked from commit 25f7af3)

* tests: skip wrong host test for SSL_NO_VERIFY (fix #139) (#140)

Since #114, we only turn
off peer verification, not host verification when the `SSL_NO_VERIFY`
variables are set. This means that the last set of tests in the "SSL no
verify override" testset *should* fail for `wrong.host.badssl.com`. That
is not what I was seeing, however — the test was still passing — which I
found puzzling but just moved on with my life at the time. It turns out
that the test *does* fail if libcurl is build with OpenSSL. Since
whether the test passes or not for that host depends on how things are
built, this change simply skips the test (by popping the URL from the
set of tested URLS for that testset).

The tests above that which use the easy hook mechanism are fixed in a
different way: for those I made the hook disable both host and peer
verification, which should fix the tests for any bad host including when
the server sends the wrong host name.

(cherry picked from commit e22219f)

* Fix input body size detection for IOBuffer(codeunits(str)) (#143)

Somewhat surprisingly, the type of this is not IOBuffer, but a related
type (Base.GenericIOBuffer{Base.CodeUnits{UInt8, String}}).

(cherry picked from commit 470b7f0)

* Typo fix: indiation -> indication (#144)

(cherry picked from commit 5f1509d)

* use Timer instead of libuv timer API

(cherry picked from commit 11493ff)

* use FDWatcher instead of libuv poll API

(cherry picked from commit 4c1d2af)

* fix wrong definition of curl_socket_t on Windows

(cherry picked from commit 2eb0491)

* Revert "stop using raw libuv API" (#156)

(cherry picked from commit c91876a)

* Revert "Revert "stop using raw libuv API" (#156)"

This reverts commit c91876a.

(cherry picked from commit 69acc13)

* add missing locks during Timer callbacks

(cherry picked from commit 43a3484)

* fix Timer usage (#158)

(cherry picked from commit 62b497e)

* Workaround for missing isopen check in FDWatcher (#161)

(possible multithread race with this still needs to be fixed)

(cherry picked from commit 7f91b8a)

* Check for timer isopen correctly (#162)

(cherry picked from commit 4250b35)

* remove trailing whitespace

(cherry picked from commit d8c626b)

* Avoid infinite recursion in `timer_callback` (#164)

Fixes #163

(cherry picked from commit a55825b)

* should also look into headers for input_size (#167)

If no content length is set while uploading some contents, Curl defaults to use
chunked transfer encoding. In some cases we want to prevent that because the
server may not support chunked transfers.

With this change, the request method will also look at the headers while
determining the input size and if found call `set_upload_size` as usual. So to
switch off chunked transfers, one must also know and set the content length
header while invoking `download` or `request` methods.

(cherry picked from commit ab628ab)

* rename: singularize add_{upload,seek}_callback

These only add one callback so having them be plural is weird.

(cherry picked from commit 5bd0826)

* add support for setting a debug callback

(cherry picked from commit 55a0c39)

* end-to-end tests for #167

This adds end-to-end tests for the changes introduced in #167.

Verbose mode is switched off for these tests, but switching it on would show that not setting content-length headers results in chunked transfer encoding while setting it prevents that. Both tests should pass.

(cherry picked from commit 911368d)

* tests: use debug option to test for non/chunked uploads

This combines the functionality from the previous two commits to not
only trigger both chunked and non-chunked uploads, but also test for
that difference by capturing and inspecting the debug events.

(cherry picked from commit 4e0408a)

* bump patch

Co-authored-by: Dilum Aluthge <dilum@aluthge.com>
Co-authored-by: Jakob Nybo Nissen <jakobnybonissen@gmail.com>
Co-authored-by: Yuto Horikawa <hyrodium@gmail.com>
Co-authored-by: Tim Holy <tim.holy@gmail.com>
Co-authored-by: Stefan Karpinski <stefan@karpinski.org>
Co-authored-by: Chris Foster <chris42f@gmail.com>
Co-authored-by: Benoît Legat <benoit.legat@gmail.com>
Co-authored-by: Jameson Nash <vtjnash@gmail.com>
Co-authored-by: Tanmay Mohapatra <tanmaykm@gmail.com>
@StefanKarpinski StefanKarpinski mentioned this pull request Mar 24, 2022
StefanKarpinski pushed a commit that referenced this pull request Mar 24, 2022
If no content length is set while uploading some contents, Curl defaults to use
chunked transfer encoding. In some cases we want to prevent that because the
server may not support chunked transfers.

With this change, the request method will also look at the headers while
determining the input size and if found call `set_upload_size` as usual. So to
switch off chunked transfers, one must also know and set the content length
header while invoking `download` or `request` methods.

(cherry picked from commit ab628ab)
StefanKarpinski pushed a commit that referenced this pull request Mar 24, 2022
This adds end-to-end tests for the changes introduced in #167.

Verbose mode is switched off for these tests, but switching it on would show that not setting content-length headers results in chunked transfer encoding while setting it prevents that. Both tests should pass.

(cherry picked from commit 911368d)
StefanKarpinski pushed a commit that referenced this pull request Mar 24, 2022
If no content length is set while uploading some contents, Curl defaults to use
chunked transfer encoding. In some cases we want to prevent that because the
server may not support chunked transfers.

With this change, the request method will also look at the headers while
determining the input size and if found call `set_upload_size` as usual. So to
switch off chunked transfers, one must also know and set the content length
header while invoking `download` or `request` methods.

(cherry picked from commit ab628ab)
StefanKarpinski pushed a commit that referenced this pull request Mar 24, 2022
This adds end-to-end tests for the changes introduced in #167.

Verbose mode is switched off for these tests, but switching it on would show that not setting content-length headers results in chunked transfer encoding while setting it prevents that. Both tests should pass.

(cherry picked from commit 911368d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants