fix content length
Some checks are pending
Build / windows (arm64) (push) Waiting to run
Build / windows (ia32) (push) Waiting to run
Build / windows (x64) (push) Waiting to run
Build / windows7 (ia32) (push) Waiting to run
Build / windows7 (x64) (push) Waiting to run
Build / linux (arm64) (push) Waiting to run
Build / linux (x64) (push) Waiting to run
Build / macos (arm64) (push) Waiting to run
Build / macos (x64) (push) Waiting to run
Build / updater (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-bin) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron) (push) Blocked by required conditions
Build / aur-release-updater (mihomo-party-electron-bin) (push) Blocked by required conditions
Build / aur-git-updater (push) Waiting to run
Build / Update WinGet Package (push) Blocked by required conditions
Build / Update Homebrew cask (push) Blocked by required conditions

This commit is contained in:
pompurin404 2024-09-27 18:14:38 +08:00
parent 35cc44faa3
commit e407c1db19
No known key found for this signature in database

View File

@ -36,11 +36,12 @@ async function mihomoHttp<T>(method: HttpMethod, path: string, data?: object): P
)
client.on('data', function (res) {
try {
const data = trimJson(res.toString().split('\r\n\r\n')[1])
const data = res.toString().split('\r\n\r\n')[1]
const json = trimJson(data)
if (res.toString().includes('HTTP/1.1 4') || res.toString().includes('HTTP/1.1 5')) {
reject(data ? JSON.parse(data) : undefined)
reject(json ? JSON.parse(json) : data)
} else {
resolve(data ? JSON.parse(data) : undefined)
resolve(json ? JSON.parse(json) : undefined)
}
} catch (e) {
reject(e)
@ -54,7 +55,7 @@ async function mihomoHttp<T>(method: HttpMethod, path: string, data?: object): P
if (data) {
const json = JSON.stringify(data)
client.write(
`${method} ${path} HTTP/1.1\r\nHost: mihomo-party\r\nContent-Type: application/json\r\nContent-Length: ${json.length}\r\n\r\n${json}`
`${method} ${path} HTTP/1.1\r\nHost: mihomo-party\r\nContent-Type: application/json\r\nContent-Length: ${Buffer.from(json).length}\r\n\r\n${json}`
)
} else {
client.write(`${method} ${path} HTTP/1.1\r\nHost: mihomo-party\r\n\r\n`)
@ -86,7 +87,7 @@ export const patchMihomoConfig = async (patch: Partial<IMihomoConfig>): Promise<
}
export const mihomoCloseConnection = async (id: string): Promise<void> => {
return await mihomoHttp('DELETE', `/connection/${id}`)
return await mihomoHttp('DELETE', `/connections/${id}`)
}
export const mihomoCloseAllConnections = async (): Promise<void> => {