download
total
parameter would remain as initialized at-1
if the"Content-Length"
header was not present
You might check that. I think I did, but I don’t recall. Even with the Content-Length header present, I don’t think it works correctly. It is present with the GitHub downloads. Also, I think the download used in the example does not have a redirect, but the larger one (that’s commented out) does. That may also affect it, not sure.
Regardless, Sketchup::Http was probably created due to the issues with OpenSSL 1.0.2/Ruby 2.2. Those issues aren’t a problem with Ruby 2.5 and later.
With most downloads, the user is probably performing some action to start them, so having an async method for something that will probably freeze the UI when it’s done is kind of pointless for most downloads. Freezing a high capacity server is one thing, but a second or two for a UI isn’t as critical.
Over time, I’ve seen enough comments about Net::HTTP not working that I thought that, given using Ruby or later, that a) it really isn’t a problem, and b) it is a mature library. Hence, some code to demo how it works.
Also, async/promises was a big thing with node.js for a while, but now it’s moving somewhat back to sync for many things, as socket based API’s don’t run async very well. Remember also that async can really strain a call stack. Using a Ruby term, think of all the binding that have to be saved with a large async call chain…