| 1 | require "lahttp" |
| 2 | require "multihttp" |
| 3 | |
| 4 | local function mycallback(url, status, data) |
| 5 | print("---------------"); |
| 6 | if status == 200 then -- HTTP OK |
| 7 | print("Received the data from "..url..":"); |
| 8 | print(data) |
| 9 | else |
| 10 | print("Received HTTP error "..status.." while downloading from "..url); |
| 11 | end |
| 12 | print("---------------"); |
| 13 | end |
| 14 | |
| 15 | local function progresscallback(batch) |
| 16 | print("Progress:"); |
| 17 | for url, progress in pairs(batch:progress()) do |
| 18 | print(url..":"); |
| 19 | for statistic, value in pairs(progress) do |
| 20 | print("", statistic..": "..value); |
| 21 | end |
| 22 | end |
| 23 | print(""); |
| 24 | end |
| 25 | |
| 26 | batch_download = multihttp.new(mycallback, { "http://www.google.com/", "http://example.com/" }); |
| 27 | |
| 28 | batch_download:set_progress_callback(progresscallback, 1); -- Call progresscallback every second |
| 29 | |
| 30 | batch_download:download(true); -- true means "don't return until all downloads are finished" |