Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/parse_http.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ var common = require('./common')
var REMOVE_IPV4_MAPPED_IPV6_RE = /^::ffff:/

function parseHttpRequest (req, options) {
options = options || {}
var s = req.url.split('?')
var params = common.querystringParse(s[1])

if (s[0] === '/announce') {
if (options.action === 'announce' || s[0] === '/announce') {
params.action = common.ACTIONS.ANNOUNCE

if (typeof params.info_hash !== 'string' || params.info_hash.length !== 20)
Expand All @@ -32,7 +33,7 @@ function parseHttpRequest (req, options) {
? req.headers['x-forwarded-for'] || req.connection.remoteAddress
: req.connection.remoteAddress.replace(REMOVE_IPV4_MAPPED_IPV6_RE, '') // force ipv4
params.addr = (common.IPV6_RE.test(params.ip) ? '[' + params.ip + ']' : params.ip) + ':' + params.port
} else if (s[0] === '/scrape') {
} else if (options.action === 'scrape' || s[0] === '/scrape') {
params.action = common.ACTIONS.SCRAPE
if (typeof params.info_hash === 'string')
params.info_hash = [ params.info_hash ]
Expand Down
8 changes: 6 additions & 2 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,16 @@ Server.prototype.getSwarm = function (infoHash) {
return swarm
}

Server.prototype.onHttpRequest = function (req, res) {
Server.prototype.onHttpRequest = function (req, res, options) {
var self = this
options = options || {}
options.trustProxy = options.trustProxy || self._trustProxy

var params
try {
params = parseHttpRequest(req, { trustProxy: self._trustProxy })
params = parseHttpRequest(req, options)
params.httpReq = req
params.httpRes = res
} catch (err) {
debug('sent error %s', err.message)
res.end(bencode.encode({
Expand Down