aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/http-files/CMakeLists.txt12
-rw-r--r--plugins/http-files/src/file_provider.vala47
-rw-r--r--plugins/http-files/src/file_sender.vala34
3 files changed, 60 insertions, 33 deletions
diff --git a/plugins/http-files/CMakeLists.txt b/plugins/http-files/CMakeLists.txt
index 77579fdb..2da46731 100644
--- a/plugins/http-files/CMakeLists.txt
+++ b/plugins/http-files/CMakeLists.txt
@@ -1,10 +1,18 @@
+set(HTTP_FILES_DEFINITIONS)
+if(USE_SOUP3)
+ set(Soup Soup3)
+ set(HTTP_FILES_DEFINITIONS ${HTTP_FILES_DEFINITIONS} SOUP_3)
+else()
+ set(Soup Soup2)
+endif()
+
find_packages(HTTP_FILES_PACKAGES REQUIRED
Gee
GLib
GModule
GObject
GTK3
- Soup
+ ${Soup}
)
vala_precompile(HTTP_FILES_VALA_C
@@ -19,6 +27,8 @@ CUSTOM_VAPIS
${CMAKE_BINARY_DIR}/exports/qlite.vapi
PACKAGES
${HTTP_FILES_PACKAGES}
+DEFINITIONS
+ ${HTTP_FILES_DEFINITIONS}
)
add_definitions(${VALA_CFLAGS})
diff --git a/plugins/http-files/src/file_provider.vala b/plugins/http-files/src/file_provider.vala
index 11885721..3a3aeb94 100644
--- a/plugins/http-files/src/file_provider.vala
+++ b/plugins/http-files/src/file_provider.vala
@@ -98,24 +98,26 @@ public class FileProvider : Dino.FileProvider, Object {
var session = new Soup.Session();
session.user_agent = @"Dino/$(Dino.get_short_version()) ";
var head_message = new Soup.Message("HEAD", http_receive_data.url);
+ head_message.request_headers.append("Accept-Encoding", "identity");
- if (head_message != null) {
- head_message.request_headers.append("Accept-Encoding", "identity");
- try {
- yield session.send_async(head_message, null);
- } catch (Error e) {
- throw new FileReceiveError.GET_METADATA_FAILED("HEAD request failed");
- }
+ try {
+#if SOUP_3
+ yield session.send_async(head_message, GLib.Priority.LOW, null);
+#else
+ yield session.send_async(head_message, null);
+#endif
+ } catch (Error e) {
+ throw new FileReceiveError.GET_METADATA_FAILED("HEAD request failed");
+ }
- string? content_type = null, content_length = null;
- head_message.response_headers.foreach((name, val) => {
- if (name.down() == "content-type") content_type = val;
- if (name.down() == "content-length") content_length = val;
- });
- file_meta.mime_type = content_type;
- if (content_length != null) {
- file_meta.size = int64.parse(content_length);
- }
+ string? content_type = null, content_length = null;
+ head_message.response_headers.foreach((name, val) => {
+ if (name.down() == "content-type") content_type = val;
+ if (name.down() == "content-length") content_length = val;
+ });
+ file_meta.mime_type = content_type;
+ if (content_length != null) {
+ file_meta.size = int64.parse(content_length);
}
return file_meta;
@@ -129,11 +131,16 @@ public class FileProvider : Dino.FileProvider, Object {
HttpFileReceiveData? http_receive_data = receive_data as HttpFileReceiveData;
if (http_receive_data == null) assert(false);
+ var session = new Soup.Session();
+ session.user_agent = @"Dino/$(Dino.get_short_version()) ";
+ var get_message = new Soup.Message("GET", http_receive_data.url);
+
try {
- var session = new Soup.Session();
- session.user_agent = @"Dino/$(Dino.get_short_version()) ";
- Soup.Request request = session.request(http_receive_data.url);
- InputStream stream = yield request.send_async(file_transfer.cancellable);
+#if SOUP_3
+ InputStream stream = yield session.send_async(get_message, GLib.Priority.LOW, file_transfer.cancellable);
+#else
+ InputStream stream = yield session.send_async(get_message, file_transfer.cancellable);
+#endif
if (file_meta.size != -1) {
return new LimitInputStream(stream, file_meta.size);
} else {
diff --git a/plugins/http-files/src/file_sender.vala b/plugins/http-files/src/file_sender.vala
index 8a22ffe1..ab81ffce 100644
--- a/plugins/http-files/src/file_sender.vala
+++ b/plugins/http-files/src/file_sender.vala
@@ -73,6 +73,7 @@ public class HttpFileSender : FileSender, Object {
}
}
+#if !SOUP_3
private static void transfer_more_bytes(InputStream stream, Soup.MessageBody body) {
uint8[] bytes = new uint8[4096];
ssize_t read = stream.read(bytes);
@@ -83,26 +84,35 @@ public class HttpFileSender : FileSender, Object {
bytes.length = (int)read;
body.append_buffer(new Soup.Buffer.take(bytes));
}
+#endif
private async void upload(FileTransfer file_transfer, HttpFileSendData file_send_data, FileMeta file_meta) throws FileSendError {
Xmpp.XmppStream? stream = stream_interactor.get_stream(file_transfer.account);
if (stream == null) return;
- Soup.Message message = new Soup.Message("PUT", file_send_data.url_up);
- message.request_headers.set_content_type(file_meta.mime_type, null);
- message.request_headers.set_content_length(file_meta.size);
+ var session = new Soup.Session();
+ session.user_agent = @"Dino/$(Dino.get_short_version()) ";
+ var put_message = new Soup.Message("PUT", file_send_data.url_up);
+#if SOUP_3
+ put_message.set_request_body(file_meta.mime_type, file_transfer.input_stream, (ssize_t) file_meta.size);
+#else
+ put_message.request_headers.set_content_type(file_meta.mime_type, null);
+ put_message.request_headers.set_content_length(file_meta.size);
+ put_message.request_body.set_accumulate(false);
+ put_message.wrote_headers.connect(() => transfer_more_bytes(file_transfer.input_stream, put_message.request_body));
+ put_message.wrote_chunk.connect(() => transfer_more_bytes(file_transfer.input_stream, put_message.request_body));
+#endif
foreach (var entry in file_send_data.headers.entries) {
- message.request_headers.append(entry.key, entry.value);
+ put_message.request_headers.append(entry.key, entry.value);
}
- message.request_body.set_accumulate(false);
- message.wrote_headers.connect(() => transfer_more_bytes(file_transfer.input_stream, message.request_body));
- message.wrote_chunk.connect(() => transfer_more_bytes(file_transfer.input_stream, message.request_body));
- Soup.Session session = new Soup.Session();
- session.user_agent = @"Dino/$(Dino.get_short_version()) ";
try {
- yield session.send_async(message, file_transfer.cancellable);
- if (message.status_code < 200 || message.status_code >= 300) {
- throw new FileSendError.UPLOAD_FAILED("HTTP status code %s".printf(message.status_code.to_string()));
+#if SOUP_3
+ yield session.send_async(put_message, GLib.Priority.LOW, file_transfer.cancellable);
+#else
+ yield session.send_async(put_message, file_transfer.cancellable);
+#endif
+ if (put_message.status_code < 200 || put_message.status_code >= 300) {
+ throw new FileSendError.UPLOAD_FAILED("HTTP status code %s".printf(put_message.status_code.to_string()));
}
} catch (Error e) {
throw new FileSendError.UPLOAD_FAILED("HTTP upload error: %s".printf(e.message));