]> Sergey Matveev's repositories - btrtrc.git/commitdiff
fix http tracker arg position (#700)
authorPreston <1033514+boypt@users.noreply.github.com>
Thu, 23 Dec 2021 01:34:16 +0000 (09:34 +0800)
committerGitHub <noreply@github.com>
Thu, 23 Dec 2021 01:34:16 +0000 (12:34 +1100)
Co-authored-by: Bot Git <bot@example.com>
tracker/http/http.go

index f45cc7c2e6ec2f17f4702c11acc215e3493d4c9d..3eed2d8034efb548a628b56a9fccc155621c6c92 100644 (file)
@@ -23,7 +23,7 @@ import (
 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 @@ func setAnnounceParams(_url *url.URL, ar *AnnounceRequest, opts AnnounceOpt) {
        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 {