-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
70 lines (63 loc) · 1.87 KB
/
proxy.js
File metadata and controls
70 lines (63 loc) · 1.87 KB
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
64
65
66
67
68
69
70
const { createTLSClient } = require("tls-client-node")
const tlsclient = createTLSClient()
const defaultHeaders = {
accept: "*/*",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-US,en;q=0.9",
"sec-ch-ua": `"Chromium";v="138", "Google Chrome";v="138", "Not=A?Brand";v="99"`,
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": '"Windows"',
"sec-fetch-dest": "empty",
"sec-fetch-mode": "cors",
"sec-fetch-site": "same-origin",
"sec-fetch-user": "?1",
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
}
function httpLowerKeyRespon(headers) {
const lowerCaseHeaders = {}
for (const key in headers) {
if (Object.prototype.hasOwnProperty.call(headers, key)) {
lowerCaseHeaders[key.toLowerCase()] = headers[key]
}
}
return lowerCaseHeaders
}
async function TLSProxyRequest(url, { method = "GET", data, headers = {}, ...other } = {}) {
try {
const datarequest = {
method: method,
headers: {
...defaultHeaders,
...headers
},
data: data,
...other,
url: new URL(url).href
}
const request = await tlsclient.request(datarequest)
return {
isError: false,
status: request?.status || 400,
headers: httpLowerKeyRespon(request?.headers || {}),
data: request?.data || null,
}
} catch (e) {
console.error("[TlsClient] ErrorRequest:", e.stack)
const request = e.response
if (request) {
return {
isError: true,
status: request?.status || 400,
headers: httpLowerKeyRespon(request?.headers || {}),
data: request?.data || null,
}
}
return {
isError: true,
status: 500,
headers: {},
data: null
}
}
}
module.exports = TLSProxyRequest