mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-14 19:36:24 +00:00
Merge pull request #215 from feross/upgradereq
Delete `socket.upgradeReq` when it is no longer needed to reduce memory usage
This commit is contained in:
commit
0c973661d2
@ -52,15 +52,27 @@ function parseWebSocketRequest (socket, opts, params) {
|
|||||||
throw new Error('invalid action in WS request: ' + params.action)
|
throw new Error('invalid action in WS request: ' + params.action)
|
||||||
}
|
}
|
||||||
|
|
||||||
params.ip = opts.trustProxy
|
// On first parse, save important data from `socket.upgradeReq` and delete it
|
||||||
? socket.upgradeReq.headers['x-forwarded-for'] || socket.upgradeReq.connection.remoteAddress
|
// to reduce memory usage.
|
||||||
: socket.upgradeReq.connection.remoteAddress.replace(common.REMOVE_IPV4_MAPPED_IPV6_RE, '') // force ipv4
|
if (socket.upgradeReq) {
|
||||||
params.port = socket.upgradeReq.connection.remotePort
|
socket.ip = opts.trustProxy
|
||||||
if (params.port) {
|
? socket.upgradeReq.headers['x-forwarded-for'] || socket.upgradeReq.connection.remoteAddress
|
||||||
params.addr = (common.IPV6_RE.test(params.ip) ? '[' + params.ip + ']' : params.ip) + ':' + params.port
|
: socket.upgradeReq.connection.remoteAddress.replace(common.REMOVE_IPV4_MAPPED_IPV6_RE, '') // force ipv4
|
||||||
|
socket.port = socket.upgradeReq.connection.remotePort
|
||||||
|
if (socket.port) {
|
||||||
|
socket.addr = (common.IPV6_RE.test(socket.ip) ? '[' + socket.ip + ']' : socket.ip) + ':' + socket.port
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.headers = socket.upgradeReq.headers
|
||||||
|
|
||||||
|
// Delete `socket.upgradeReq` when it is no longer needed to reduce memory usage
|
||||||
|
socket.upgradeReq = null
|
||||||
}
|
}
|
||||||
|
|
||||||
params.headers = socket.upgradeReq.headers
|
params.ip = socket.ip
|
||||||
|
params.port = socket.port
|
||||||
|
params.addr = socket.addr
|
||||||
|
params.headers = socket.headers
|
||||||
|
|
||||||
return params
|
return params
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user