Sean, On 10 May 2012, at 20:37, Sven Van Caekenberghe wrote:
On 10 May 2012, at 17:52, Sean P. DeNigris wrote:
Sven Van Caekenberghe wrote
My question to you is, what are you trying to accomplish ? Check the size first, before doing a download maybe ?
Exactly. I wanted to do it that way so I could output a log message if the file had been modified. In the end, I decided the complexity wasn't worth it in this case and decided to do "client request headers at: 'If-Modified-Since' put: self lastDownloadModified", which works great, but doesn't provide a hook to say "file has changed, downloading..."
OK, that is a good, useful use case. It is doable by handling the non-modified response. #downloadTo: is new, maybe it has to be revised a bit to be more general.
Well, it does actually work, try (with latest Zn update): ZnClient new beOneShot; url: 'http://caretaker.wolf359.be/small.html'; setIfModifiedSince: Date yesterday; downloadTo: '/tmp/'. ZnClient new beOneShot; url: 'http://caretaker.wolf359.be/small.html'; setIfModifiedSince: DateAndTime unixEpoch; downloadTo: '/tmp/'. I guess you'll want to take the reference date from the previously saved file, but that is an exercise left to the reader ;-) The first will return false (and does no download), the second will return true (and does the download). Of course, the server has to honor the protocol (here Apache does). The reason this works, is because a 304 is not classified as a success. I just added #setIfModifiedSince on ZnClient, it did already exist on ZnRequest, as a convenience. Regards, Sven -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill