From: Sergey Matveev Date: Fri, 13 Feb 2026 13:32:21 +0000 (+0300) Subject: Add pri/geo attributes to Links X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c9fc71de412259c29217ee7559e1720327045b61;p=godlighty.git Add pri/geo attributes to Links --- diff --git a/godlighty.go b/godlighty.go index 834266e..60c1c4b 100644 --- a/godlighty.go +++ b/godlighty.go @@ -1,6 +1,6 @@ // Highly-customizable HTTP, HTTP/2, HTTPS server package godlighty -const Version = "godlighty/0.10.0" +const Version = "godlighty/0.11.0" var BindAddr string diff --git a/handler.go b/handler.go index d31857a..43fa36a 100644 --- a/handler.go +++ b/handler.go @@ -268,7 +268,14 @@ IndexLookuped: `>; rel=describedby; type="application/metalink4+xml"`, ) for _, u := range forHTTP.URLs { - w.Header().Add("Link", "<"+u+">; rel=duplicate") + s := "<" + u.URL + ">; rel=duplicate" + if u.Priority != 0 { + s += "; pri=" + strconv.Itoa(int(u.Priority)) + } + if u.Location != "" { + s += "; geo=" + u.Location + } + w.Header().Add("Link", s) } for name, digest := range forHTTP.Hashes { w.Header().Add("Digest", name+"="+base64.StdEncoding.EncodeToString(digest)) diff --git a/meta4/parse.go b/meta4/parse.go index 7a90e46..ca128f1 100644 --- a/meta4/parse.go +++ b/meta4/parse.go @@ -37,7 +37,7 @@ var KnownHashes = map[string]string{ type ForHTTP struct { Hashes map[string][]byte - URLs []string + URLs []URL Torrents []string } @@ -63,9 +63,7 @@ func Parse(fn string, data []byte) (*ForHTTP, error) { } forHTTP.Hashes[name] = digest } - for _, u := range f.URLs { - forHTTP.URLs = append(forHTTP.URLs, u.URL) - } + forHTTP.URLs = f.URLs for _, m := range f.MetaURLs { if m.MediaType == "torrent" { forHTTP.Torrents = append(forHTTP.Torrents, m.URL) diff --git a/meta4/scheme.go b/meta4/scheme.go index 82ce4a5..a082c9b 100644 --- a/meta4/scheme.go +++ b/meta4/scheme.go @@ -44,8 +44,10 @@ type File struct { } type URL struct { - XMLName xml.Name `xml:"url"` - URL string `xml:",chardata"` + XMLName xml.Name `xml:"url"` + Location string `xml:"location,attr"` + Priority uint `xml:"priority,attr"` + URL string `xml:",chardata"` } type Signature struct {