@tauri-apps/plugin-http 2.4.1 → 2.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-js/index.cjs CHANGED
@@ -124,16 +124,15 @@ async function fetch(input, init) {
124
124
  controller.error(ERROR_REQUEST_CANCELLED);
125
125
  return;
126
126
  }
127
- // close when the signal to close (an empty chunk)
128
- // is sent from the IPC.
129
- if (res instanceof ArrayBuffer ? res.byteLength == 0 : res.length == 0) {
127
+ const resUint8 = new Uint8Array(res);
128
+ const lastByte = resUint8[resUint8.byteLength - 1];
129
+ const actualRes = resUint8.slice(0, resUint8.byteLength - 1);
130
+ // close when the signal to close (last byte is 1) is sent from the IPC.
131
+ if (lastByte == 1) {
130
132
  controller.close();
131
133
  return;
132
134
  }
133
- // the content conversion (like .text(), .json(), etc.) in Response
134
- // must have Uint8Array as its content, else it will
135
- // have untraceable error that's hard to debug.
136
- controller.enqueue(new Uint8Array(res));
135
+ controller.enqueue(actualRes);
137
136
  };
138
137
  // run a non-blocking body stream fetch
139
138
  core.invoke('plugin:http|fetch_read_body', {
@@ -148,12 +147,11 @@ async function fetch(input, init) {
148
147
  status,
149
148
  statusText
150
149
  });
151
- // url and headers are read only properties
152
- // but seems like we can set them like this
150
+ // Set `Response` properties that are ignored by the
151
+ // constructor, like url and some headers
153
152
  //
154
- // we define theme like this, because using `Response`
155
- // constructor, it removes url and some headers
156
- // like `set-cookie` headers
153
+ // Since url and headers are read only properties
154
+ // this is the only way to set them.
157
155
  Object.defineProperty(res, 'url', { value: url });
158
156
  Object.defineProperty(res, 'headers', {
159
157
  value: new Headers(responseHeaders)
package/dist-js/index.js CHANGED
@@ -122,16 +122,15 @@ async function fetch(input, init) {
122
122
  controller.error(ERROR_REQUEST_CANCELLED);
123
123
  return;
124
124
  }
125
- // close when the signal to close (an empty chunk)
126
- // is sent from the IPC.
127
- if (res instanceof ArrayBuffer ? res.byteLength == 0 : res.length == 0) {
125
+ const resUint8 = new Uint8Array(res);
126
+ const lastByte = resUint8[resUint8.byteLength - 1];
127
+ const actualRes = resUint8.slice(0, resUint8.byteLength - 1);
128
+ // close when the signal to close (last byte is 1) is sent from the IPC.
129
+ if (lastByte == 1) {
128
130
  controller.close();
129
131
  return;
130
132
  }
131
- // the content conversion (like .text(), .json(), etc.) in Response
132
- // must have Uint8Array as its content, else it will
133
- // have untraceable error that's hard to debug.
134
- controller.enqueue(new Uint8Array(res));
133
+ controller.enqueue(actualRes);
135
134
  };
136
135
  // run a non-blocking body stream fetch
137
136
  invoke('plugin:http|fetch_read_body', {
@@ -146,12 +145,11 @@ async function fetch(input, init) {
146
145
  status,
147
146
  statusText
148
147
  });
149
- // url and headers are read only properties
150
- // but seems like we can set them like this
148
+ // Set `Response` properties that are ignored by the
149
+ // constructor, like url and some headers
151
150
  //
152
- // we define theme like this, because using `Response`
153
- // constructor, it removes url and some headers
154
- // like `set-cookie` headers
151
+ // Since url and headers are read only properties
152
+ // this is the only way to set them.
155
153
  Object.defineProperty(res, 'url', { value: url });
156
154
  Object.defineProperty(res, 'headers', {
157
155
  value: new Headers(responseHeaders)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-http",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "license": "MIT OR Apache-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"