fix
This commit is contained in:
@@ -1,13 +1,20 @@
|
||||
export function byteStringResponseHeaders(headers: Record<string, string[]> = {}) {
|
||||
export function byteStringResponseHeaders(headers: Record<string, string | string[]> = {}) {
|
||||
return Object.fromEntries(Object.entries(headers).map(([name, values]) => [
|
||||
name,
|
||||
values.map((value) => value.replace(/[^\x00-\xff]+/gu, encodeURIComponent)),
|
||||
(Array.isArray(values) ? values : [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) })
|
||||
callback({
|
||||
responseHeaders: byteStringResponseHeaders(details.responseHeaders),
|
||||
statusLine: asciiStatusLine(details.statusLine),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export function asciiStatusLine(line: string) {
|
||||
return /[^\x20-\x7e]/.test(line) ? line.replace(/^(HTTP\/\S+\s+\d{3}).*$/, '$1 ') : line
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user