mirror of
https://github.com/webtorrent/bittorrent-tracker.git
synced 2024-12-14 11:26:25 +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)
|
||||
}
|
||||
|
||||
params.ip = opts.trustProxy
|
||||
? socket.upgradeReq.headers['x-forwarded-for'] || socket.upgradeReq.connection.remoteAddress
|
||||
: socket.upgradeReq.connection.remoteAddress.replace(common.REMOVE_IPV4_MAPPED_IPV6_RE, '') // force ipv4
|
||||
params.port = socket.upgradeReq.connection.remotePort
|
||||
if (params.port) {
|
||||
params.addr = (common.IPV6_RE.test(params.ip) ? '[' + params.ip + ']' : params.ip) + ':' + params.port
|
||||
// On first parse, save important data from `socket.upgradeReq` and delete it
|
||||
// to reduce memory usage.
|
||||
if (socket.upgradeReq) {
|
||||
socket.ip = opts.trustProxy
|
||||
? socket.upgradeReq.headers['x-forwarded-for'] || socket.upgradeReq.connection.remoteAddress
|
||||
: 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user