@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 +33 -29
- package/dist-js/index.js +33 -29
- package/package.json +1 -1
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
});
|