Skip to content

Commit

Permalink
Merge pull request #894 from haoming29/metalink-for-origin
Browse files Browse the repository at this point in the history
Add Metalink for redirect to origin
  • Loading branch information
jhiemstrawisc authored Mar 6, 2024
2 parents 4d653b9 + 9fffc6c commit 215592a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
20 changes: 19 additions & 1 deletion director/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,12 @@ func redirectToOrigin(ginCtx *gin.Context) {
ginCtx.String(http.StatusNotFound, "There are currently no origins exporting the provided namespace prefix\n")
return
}
// if err != nil, depth == 0, which is the default value for depth
// so we can use it as the value for the header even with err
depth, err := getLinkDepth(reqPath, namespaceAd.Path)
if err != nil {
log.Errorf("Failed to get depth attribute for the redirecting request to %q, with best match namespace prefix %q", reqPath, namespaceAd.Path)
}

originAds, err = sortServers(ipAddr, originAds)
if err != nil {
Expand All @@ -360,8 +366,20 @@ func redirectToOrigin(ginCtx *gin.Context) {
return
}

var colUrl string
linkHeader := ""
first := true
for idx, ad := range originAds {
if first {
first = false
} else {
linkHeader += ", "
}
redirectURL := getRedirectURL(reqPath, ad, !namespaceAd.PublicRead)
linkHeader += fmt.Sprintf(`<%s>; rel="duplicate"; pri=%d; depth=%d`, redirectURL.String(), idx+1, depth)
}
ginCtx.Writer.Header()["Link"] = []string{linkHeader}

var colUrl string
if namespaceAd.PublicRead {
colUrl = originAds[0].URL.String()
} else {
Expand Down
1 change: 1 addition & 0 deletions xrootd/origin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func TestS3OriginConfig(t *testing.T) {
viper.Set("Origin.EnableVoms", false)
viper.Set("Origin.SelfTest", false)
viper.Set("Origin.Port", 0)
viper.Set("Server.WebPort", 0)
viper.Set("TLSSkipVerify", true)

mockupCancel := originMockup(ctx, egrp, t)
Expand Down

0 comments on commit 215592a

Please sign in to comment.