fix http tracker arg position (#700)

Co-authored-by: Bot Git <bot@example.com>
This commit is contained in:
Preston 2021-12-23 09:34:16 +08:00 committed by GitHub
parent b6cc93c0be
commit b831060d6e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 2 deletions

View File

@ -23,7 +23,7 @@ import (
var vars = expvar.NewMap("tracker/http") var vars = expvar.NewMap("tracker/http")
func setAnnounceParams(_url *url.URL, ar *AnnounceRequest, opts AnnounceOpt) { 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("key", strconv.FormatInt(int64(ar.Key), 10))
q.Set("info_hash", string(ar.InfoHash[:])) q.Set("info_hash", string(ar.InfoHash[:]))
@ -64,7 +64,14 @@ func setAnnounceParams(_url *url.URL, ar *AnnounceRequest, opts AnnounceOpt) {
doIp("ipv6", opts.ClientIp6) doIp("ipv6", opts.ClientIp6)
// We're operating purely on query-escaped strings, where + would have already been encoded to // 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. // %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 { type AnnounceOpt struct {