summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Chimento <philip.chimento@gmail.com>2022-08-11 06:05:49 +0000
committerPhilip Chimento <philip.chimento@gmail.com>2022-08-11 06:05:49 +0000
commitb6c1ccb69f8734b794dbc7ccc6f95e36eb85fbd7 (patch)
treeed15e3d8ac85138f2808da73a8188e311309ce76
parent2a1930b0ccc47bbd550e6cee453ca395e7496b10 (diff)
parenta878815969063bef256295edd5dfb65cc22e51f3 (diff)
downloadgjs-b6c1ccb69f8734b794dbc7ccc6f95e36eb85fbd7.tar.gz
Merge branch 'andyholmes/fix-http-example' into 'master'
examples: support no content-length in http-client.js Closes #498 See merge request GNOME/gjs!787
-rw-r--r--examples/http-client.js12
1 files changed, 9 insertions, 3 deletions
diff --git a/examples/http-client.js b/examples/http-client.js
index 5f1d7d94..dd0a8878 100644
--- a/examples/http-client.js
+++ b/examples/http-client.js
@@ -6,6 +6,7 @@
import Soup from 'gi://Soup?version=3.0';
import GLib from 'gi://GLib';
+import Gio from 'gi://Gio';
const loop = GLib.MainLoop.new(null, false);
@@ -18,11 +19,12 @@ const decoder = new TextDecoder();
session.send_async(message, null, null, send_async_callback);
-function read_bytes_async_callback(inputStream, res) {
+function splice_callback(outputStream, result) {
let data;
try {
- data = inputStream.read_bytes_finish(res);
+ outputStream.splice_finish(outputStream, result);
+ data = outputStream.steal_as_bytes();
} catch (err) {
logError(err);
loop.quit();
@@ -51,8 +53,12 @@ function send_async_callback(self, res) {
response_headers.foreach((name, value) => {
console.log(name, ':', value);
});
+ const contentType_ = response_headers.get_one('content-type');
- inputStream.read_bytes_async(response_headers.get_one('content-length'), null, null, read_bytes_async_callback);
+ const outputStream = Gio.MemoryOutputStream.new_resizable();
+ outputStream.splice_async(inputStream,
+ Gio.OutputStreamSpliceFlags.CLOSE_TARGET,
+ GLib.PRIORITY_DEFAULT, null, splice_callback);
}
loop.run();