@tauri-apps/plugin-http 2.4.2 → 2.4.4

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
@@ -115,35 +115,39 @@ async function fetch(input, init) {
115
115
  const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await core.invoke('plugin:http|fetch_send', {
116
116
  rid
117
117
  });
118
- const readableStreamBody = new ReadableStream({
119
- start: (controller) => {
120
- const streamChannel = new core.Channel();
121
- streamChannel.onmessage = (res) => {
122
- // close early if aborted
123
- if (signal?.aborted) {
124
- controller.error(ERROR_REQUEST_CANCELLED);
125
- return;
126
- }
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) {
132
- controller.close();
133
- return;
134
- }
135
- controller.enqueue(actualRes);
136
- };
137
- // run a non-blocking body stream fetch
138
- core.invoke('plugin:http|fetch_read_body', {
139
- rid: responseRid,
140
- streamChannel
141
- }).catch((e) => {
142
- controller.error(e);
143
- });
144
- }
145
- });
146
- const res = new Response(readableStreamBody, {
118
+ // no body for 101, 103, 204, 205 and 304
119
+ // see https://fetch.spec.whatwg.org/#null-body-status
120
+ const body = [101, 103, 204, 205, 304].includes(status)
121
+ ? null
122
+ : new ReadableStream({
123
+ start: (controller) => {
124
+ const streamChannel = new core.Channel();
125
+ streamChannel.onmessage = (res) => {
126
+ // close early if aborted
127
+ if (signal?.aborted) {
128
+ controller.error(ERROR_REQUEST_CANCELLED);
129
+ return;
130
+ }
131
+ const resUint8 = new Uint8Array(res);
132
+ const lastByte = resUint8[resUint8.byteLength - 1];
133
+ const actualRes = resUint8.slice(0, resUint8.byteLength - 1);
134
+ // close when the signal to close (last byte is 1) is sent from the IPC.
135
+ if (lastByte == 1) {
136
+ controller.close();
137
+ return;
138
+ }
139
+ controller.enqueue(actualRes);
140
+ };
141
+ // run a non-blocking body stream fetch
142
+ core.invoke('plugin:http|fetch_read_body', {
143
+ rid: responseRid,
144
+ streamChannel
145
+ }).catch((e) => {
146
+ controller.error(e);
147
+ });
148
+ }
149
+ });
150
+ const res = new Response(body, {
147
151
  status,
148
152
  statusText
149
153
  });
package/dist-js/index.js CHANGED
@@ -113,35 +113,39 @@ async function fetch(input, init) {
113
113
  const { status, statusText, url, headers: responseHeaders, rid: responseRid } = await invoke('plugin:http|fetch_send', {
114
114
  rid
115
115
  });
116
- const readableStreamBody = new ReadableStream({
117
- start: (controller) => {
118
- const streamChannel = new Channel();
119
- streamChannel.onmessage = (res) => {
120
- // close early if aborted
121
- if (signal?.aborted) {
122
- controller.error(ERROR_REQUEST_CANCELLED);
123
- return;
124
- }
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) {
130
- controller.close();
131
- return;
132
- }
133
- controller.enqueue(actualRes);
134
- };
135
- // run a non-blocking body stream fetch
136
- invoke('plugin:http|fetch_read_body', {
137
- rid: responseRid,
138
- streamChannel
139
- }).catch((e) => {
140
- controller.error(e);
141
- });
142
- }
143
- });
144
- const res = new Response(readableStreamBody, {
116
+ // no body for 101, 103, 204, 205 and 304
117
+ // see https://fetch.spec.whatwg.org/#null-body-status
118
+ const body = [101, 103, 204, 205, 304].includes(status)
119
+ ? null
120
+ : new ReadableStream({
121
+ start: (controller) => {
122
+ const streamChannel = new Channel();
123
+ streamChannel.onmessage = (res) => {
124
+ // close early if aborted
125
+ if (signal?.aborted) {
126
+ controller.error(ERROR_REQUEST_CANCELLED);
127
+ return;
128
+ }
129
+ const resUint8 = new Uint8Array(res);
130
+ const lastByte = resUint8[resUint8.byteLength - 1];
131
+ const actualRes = resUint8.slice(0, resUint8.byteLength - 1);
132
+ // close when the signal to close (last byte is 1) is sent from the IPC.
133
+ if (lastByte == 1) {
134
+ controller.close();
135
+ return;
136
+ }
137
+ controller.enqueue(actualRes);
138
+ };
139
+ // run a non-blocking body stream fetch
140
+ invoke('plugin:http|fetch_read_body', {
141
+ rid: responseRid,
142
+ streamChannel
143
+ }).catch((e) => {
144
+ controller.error(e);
145
+ });
146
+ }
147
+ });
148
+ const res = new Response(body, {
145
149
  status,
146
150
  statusText
147
151
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tauri-apps/plugin-http",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "license": "MIT OR Apache-2.0",
5
5
  "authors": [
6
6
  "Tauri Programme within The Commons Conservancy"