-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpostwoman_extension_hook_patch.txt
63 lines (60 loc) · 1.57 KB
/
postwoman_extension_hook_patch.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { fetch } from "@tauri-apps/plugin-http"
declare global {
interface Window {
__TAURI__?: any,
}
}
console.info(`executing extension strategy`)
if (window.__TAURI__ && window.__TAURI__.http) {
console.info(`injected tauri extension strategy`)
window.__POSTWOMAN_EXTENSION_HOOK__ = {
cancelRequest: () => {},
sendRequest: async ({
url,
method,
headers,
params,
data,
}: any): Promise<any> => {
try {
let body = data
if(method === 'GET' || method === 'HEAD') {
body = null
}
const startTime = Date.now()
const response = await fetch(url, {
method,
headers,
body,
})
const endTime = Date.now()
const responseData = await response.arrayBuffer()
const { headers: responseHeaders, status, statusText } = response
console.info(`tauri fetch response`, response)
return {
...response,
headers: Object.fromEntries(responseHeaders.entries()),
status,
statusText,
data: responseData,
config: {
timeData: {
startTime,
endTime,
}
},
}
} catch (error) {
console.info(`tauri fetch got error: `, error)
return {
headers: {},
status: 500,
statusText: "",
data: new TextEncoder().encode(`tauri fetch got error: ${error}`),
config: {},
}
}
},
getVersion: () => ({ major: 0, minor: 1, patch: 0 }),
}
}