This commit is contained in:
2026-10-18 23:48:36 +07:00
parent d3681d9df5
commit a58f0866d3
4 changed files with 83 additions and 0 deletions
+13
View File
@@ -0,0 +1,13 @@
export function byteStringResponseHeaders(headers: Record<string, string[]> = {}) {
return Object.fromEntries(Object.entries(headers).map(([name, values]) => [
name,
values.map((value) => value.replace(/[^\x00-\xff]+/gu, encodeURIComponent)),
]))
}
export function prepareFetchHeaders(target: Electron.Session) {
// Electron net.fetch throws outside its promise when a response header contains Unicode.
target.webRequest.onHeadersReceived((details, callback) => {
callback({ responseHeaders: byteStringResponseHeaders(details.responseHeaders) })
})
}