http-files: async file download

This commit is contained in:
fiaxh 2017-11-24 00:38:09 +01:00
parent 2f6878a523
commit 1e011852e0

View file

@ -39,7 +39,7 @@ public class FileProvider : Dino.FileProvider, Object {
var session = new Soup.Session();
var head_message = new Soup.Message("HEAD", message.body);
if (head_message != null) {
session.send_message(head_message);
session.send_async.begin(head_message, null, (obj, res) => {
string? content_type = null, content_length = null;
print(message.body + ":\n");
head_message.response_headers.foreach((name, val) => {
@ -49,9 +49,10 @@ public class FileProvider : Dino.FileProvider, Object {
});
if (/*content_type != null && content_type.has_prefix("image") &&*/ content_length != null && int.parse(content_length) < 5000000) {
FileTransfer file_transfer = new FileTransfer();
try {
Soup.Request request = session.request(message.body);
file_transfer.input_stream = request.send();
request.send_async.begin(null, (obj, res) => {
try {
file_transfer.input_stream = request.send_async.end(res);
} catch (Error e) {
return;
}
@ -69,7 +70,9 @@ public class FileProvider : Dino.FileProvider, Object {
file_transfer.provider = 0;
file_transfer.info = message.body;
file_incoming(file_transfer);
});
}
});
}
}
}