]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Save extra http Request alloc in webseed request
authorMatt Joiner <anacrolix@gmail.com>
Wed, 7 Feb 2024 02:56:49 +0000 (13:56 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 7 Feb 2024 02:56:49 +0000 (13:56 +1100)
webseed/client.go
webseed/request.go

index ac42b8a427c3d6fe369f159e125611ffda434aa8..d5ae3ac1db51528b56f2b50c52f2329c5f7b130e 100644 (file)
@@ -79,13 +79,13 @@ func (ws *Client) NewRequest(r RequestSpec) Request {
        var requestParts []requestPart
        if !ws.fileIndex.Locate(r, func(i int, e segments.Extent) bool {
                req, err := newRequest(
+                       ctx,
                        ws.Url, i, ws.info, e.Start, e.Length,
                        ws.PathEscaper,
                )
                if err != nil {
                        panic(err)
                }
-               req = req.WithContext(ctx)
                part := requestPart{
                        req:                 req,
                        result:              make(chan requestPartResult, 1),
index 53fe6dba1e3b1fe13750ae61e247ec4669031afd..a8aefab3b3018a0d2ee60709bdc7d564801524ba 100644 (file)
@@ -1,6 +1,7 @@
 package webseed
 
 import (
+       "context"
        "fmt"
        "net/http"
        "net/url"
@@ -46,6 +47,7 @@ func trailingPath(
 
 // Creates a request per BEP 19.
 func newRequest(
+       ctx context.Context,
        url_ string, fileIndex int,
        info *metainfo.Info,
        offset, length int64,
@@ -57,7 +59,7 @@ func newRequest(
                // for things like spaces and '#'.
                url_ += trailingPath(info.Name, fileInfo.Path, pathEscaper)
        }
-       req, err := http.NewRequest(http.MethodGet, url_, nil)
+       req, err := http.NewRequestWithContext(ctx, http.MethodGet, url_, nil)
        if err != nil {
                return nil, err
        }