]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Expose webseed.EscapePath
authorMatt Joiner <anacrolix@gmail.com>
Wed, 23 Feb 2022 07:03:38 +0000 (18:03 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 23 Feb 2022 07:03:52 +0000 (18:03 +1100)
webseed/request.go

index 6d62ccb61355dc83bd05008ad231a31c472ff97f..4e3ef6091472ffee381219c10d71c84a42ee042d 100644 (file)
@@ -10,10 +10,12 @@ import (
        "github.com/anacrolix/torrent/metainfo"
 )
 
-func trailingPath(infoName string, pathComps []string) string {
+// Escapes path name components suitable for appending to a webseed URL. This works for converting
+// S3 object keys to URLs too.
+func EscapePath(pathComps []string) string {
        return path.Join(
                func() (ret []string) {
-                       for _, comp := range append([]string{infoName}, pathComps...) {
+                       for _, comp := range pathComps {
                                ret = append(ret, url.QueryEscape(comp))
                        }
                        return
@@ -21,6 +23,10 @@ func trailingPath(infoName string, pathComps []string) string {
        )
 }
 
+func trailingPath(infoName string, fileComps []string) string {
+       return EscapePath(append([]string{infoName}, fileComps...))
+}
+
 // Creates a request per BEP 19.
 func NewRequest(url_ string, fileIndex int, info *metainfo.Info, offset, length int64) (*http.Request, error) {
        fileInfo := info.UpvertedFiles()[fileIndex]