Skip to content

Commit f888502

Browse files
Legend-MasterlucasfernogWSH032
authored
fix(core): use Headers in sendIpcMessage (#13227)
* Use `Headers` in `sendIpcMessage` * Add change file * Change files * Don't use optional chaining Seems like we have changed it in #9530 deliberately, so preserving it in this change * do not let the tauri headers to be overwritten Co-authored-by: Sean Wang <126865849+WSH032@users.noreply.github.com> * use HeadersInit on the type definition --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app> Co-authored-by: Sean Wang <126865849+WSH032@users.noreply.github.com>
1 parent 577c7ff commit f888502

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch:bug
3+
---
4+
5+
`invoke` will now properly throw when `options.headers` contains non-ascii characters instead of silently replacing them

.changes/invoke-headers.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch:bug
3+
---
4+
5+
Fix `invoke` ignores the headers option if it's an `Headers`

crates/tauri/scripts/ipc-protocol.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@
2727
&& (canUseCustomProtocol || cmd === fetchChannelDataCommand)
2828
) {
2929
const { contentType, data } = processIpcMessage(payload)
30+
31+
const headers = new Headers((options && options.headers) || {})
32+
headers.set('Content-Type', contentType)
33+
headers.set('Tauri-Callback', callback)
34+
headers.set('Tauri-Error', error)
35+
headers.set('Tauri-Invoke-Key', __TAURI_INVOKE_KEY__)
36+
3037
fetch(window.__TAURI_INTERNALS__.convertFileSrc(cmd, 'ipc'), {
3138
method: 'POST',
3239
body: data,
33-
headers: {
34-
'Content-Type': contentType,
35-
'Tauri-Callback': callback,
36-
'Tauri-Error': error,
37-
'Tauri-Invoke-Key': __TAURI_INVOKE_KEY__,
38-
...((options && options.headers) || {})
39-
}
40+
headers
4041
})
4142
.then((response) => {
4243
const cb =

packages/api/src/core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ type InvokeArgs = Record<string, unknown> | number[] | ArrayBuffer | Uint8Array
220220
* @since 2.0.0
221221
*/
222222
interface InvokeOptions {
223-
headers: Headers | Record<string, string>
223+
headers: HeadersInit
224224
}
225225

226226
/**

0 commit comments

Comments
 (0)