- if _, err = os.Stat(pth + Meta4Ext); err == nil {
- w.Header().Set("Link", "<"+path.Base(pth)+Meta4Ext+`>; rel=describedby; type="application/metalink4+xml"`)
+ if meta4fi, err := os.Stat(pth + meta4.Ext); err == nil {
+ if meta4fi.Size() > meta4.MaxSize {
+ goto SkipMeta4
+ }
+ meta4Raw, err := os.ReadFile(pth + meta4.Ext)
+ if err != nil {
+ goto SkipMeta4
+ }
+ base := path.Base(pth)
+ forHTTP, err := meta4.Parse(base, meta4Raw)
+ if err != nil {
+ goto SkipMeta4
+ }
+ w.Header().Add("Link", "<"+base+meta4.Ext+
+ `>; rel=describedby; type="application/metalink4+xml"`,
+ )
+ for _, u := range forHTTP.URLs {
+ w.Header().Add("Link", "<"+u+">; rel=duplicate")
+ }
+ for name, digest := range forHTTP.Hashes {
+ w.Header().Add("Digest", name+"="+base64.StdEncoding.EncodeToString(digest))
+ }
+ for _, u := range forHTTP.Torrents {
+ w.Header().Add("Link", "<"+u+`>; rel=describedby; type="application/x-bittorrent"`)
+ }