tracker/http/http.go | 11 +++++++++-- diff --git a/tracker/http/http.go b/tracker/http/http.go index f45cc7c2e6ec2f17f4702c11acc215e3493d4c9d..3eed2d8034efb548a628b56a9fccc155621c6c92 100644 --- a/tracker/http/http.go +++ b/tracker/http/http.go @@ -23,7 +23,7 @@ var vars = expvar.NewMap("tracker/http") func setAnnounceParams(_url *url.URL, ar *AnnounceRequest, opts AnnounceOpt) { - q := _url.Query() + q := url.Values{} q.Set("key", strconv.FormatInt(int64(ar.Key), 10)) q.Set("info_hash", string(ar.InfoHash[:])) @@ -64,7 +64,14 @@ doIp("ipv4", opts.ClientIp4) doIp("ipv6", opts.ClientIp6) // We're operating purely on query-escaped strings, where + would have already been encoded to // %2B, and + has no other special meaning. See https://github.com/anacrolix/torrent/issues/534. - _url.RawQuery = strings.ReplaceAll(q.Encode(), "+", "%20") + qstr := strings.ReplaceAll(q.Encode(), "+", "%20") + + // Some private trackers require the original query param to be in the first position. + if _url.RawQuery != "" { + _url.RawQuery += "&" + qstr + } else { + _url.RawQuery = qstr + } } type AnnounceOpt struct {