[Pharo-project] Zinc: HEAD and then GET
Why does one of the following work, and the other not? fileUrl := 'https://ci.lille.inria.fr/pharo/view/Pharo%201.4/job/Pharo%201.4/lastSuccess...' asUrl. "This succeeds in downloading the file" c := ZnClient new. c head: fileUrl; yourself. c url: fileUrl; downloadTo: targetPath; yourself. "This fails with a HTTP 400" c := ZnClient new. c url: fileUrl. c head; yourself. c resetRequestIfNeeded; "fails with or without this line" downloadTo: targetPath; yourself. -- View this message in context: http://forum.world.st/Zinc-HEAD-and-then-GET-tp4623719.html Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
Hi Sean, On 10 May 2012, at 16:56, Sean P. DeNigris wrote:
Why does one of the following work, and the other not?
fileUrl := 'https://ci.lille.inria.fr/pharo/view/Pharo%201.4/job/Pharo%201.4/lastSuccess...' asUrl.
"This succeeds in downloading the file" c := ZnClient new. c head: fileUrl; yourself. c url: fileUrl; downloadTo: targetPath; yourself.
"This fails with a HTTP 400" c := ZnClient new. c url: fileUrl. c head; yourself. c resetRequestIfNeeded; "fails with or without this line" downloadTo: targetPath; yourself.
I understand the problem, but this is really internal stuff of ZnClient. Yes, you can reuse a ZnClient instance to do multiple requests, but in second example, you do not re-specify the second request completely. There is no provision to do that. I will think about it. But #resetRequestIfNeeded is private API. And the state management is tricky right now. My question to you is, what are you trying to accomplish ? Check the size first, before doing a download maybe ? Sven -- Sven Van Caekenberghe http://stfx.eu Smalltalk is the Red Pill
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..." -- View this message in context: http://forum.world.st/Zinc-HEAD-and-then-GET-tp4623719p4623847.html Sent from the Pharo Smalltalk mailing list archive at Nabble.com.
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. Thanks for all the feedback, real usage help a lot to improve Zn (and Pharo). But now I am going to force myself to writing documentation (or Stef will throw me out of the PharoConf). Sven
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
participants (2)
-
Sean P. DeNigris -
Sven Van Caekenberghe