Skip to content

Commit

Permalink
Fix director default response and add HEAD as allowed verb
Browse files Browse the repository at this point in the history
  • Loading branch information
jhiemstrawisc committed Mar 27, 2024
1 parent e60b5d3 commit 2764b38
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions director/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ func ShortcutMiddleware(defaultResponse string) gin.HandlerFunc {
// If we're configured for cache mode or we haven't set the flag,
// we should use cache middleware
if defaultResponse == "cache" {
if !strings.HasPrefix(c.Request.URL.Path, "/api/v1.0/director/") {
if !strings.HasPrefix(c.Request.URL.Path, "/api/v1.0/director/") && (c.Request.Method == "GET" || c.Request.Method == "HEAD") {
c.Request.URL.Path = "/api/v1.0/director/object" + c.Request.URL.Path
redirectToCache(c)
c.Abort()
Expand All @@ -500,7 +500,7 @@ func ShortcutMiddleware(defaultResponse string) gin.HandlerFunc {
// If the path starts with the correct prefix, continue with the next handler
c.Next()
} else if defaultResponse == "origin" {
if !strings.HasPrefix(c.Request.URL.Path, "/api/v1.0/director/") {
if !strings.HasPrefix(c.Request.URL.Path, "/api/v1.0/director/") && (c.Request.Method == "GET" || c.Request.Method == "HEAD") {
c.Request.URL.Path = "/api/v1.0/director/origin" + c.Request.URL.Path
redirectToOrigin(c)
c.Abort()
Expand Down Expand Up @@ -828,7 +828,9 @@ func RegisterDirectorAPI(ctx context.Context, router *gin.RouterGroup) {
{
// Establish the routes used for cache/origin redirection
directorAPIV1.GET("/object/*any", redirectToCache)
directorAPIV1.HEAD("/object/*any", redirectToCache)
directorAPIV1.GET("/origin/*any", redirectToOrigin)
directorAPIV1.HEAD("/origin/*any", redirectToOrigin)
directorAPIV1.PUT("/origin/*any", redirectToOrigin)
directorAPIV1.POST("/registerOrigin", func(gctx *gin.Context) { registerServeAd(ctx, gctx, server_structs.OriginType) })
directorAPIV1.POST("/registerCache", func(gctx *gin.Context) { registerServeAd(ctx, gctx, server_structs.CacheType) })
Expand Down
5 changes: 3 additions & 2 deletions launchers/director_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ import (
"fmt"

"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"

"github.com/pelicanplatform/pelican/config"
"github.com/pelicanplatform/pelican/director"
"github.com/pelicanplatform/pelican/metrics"
"github.com/pelicanplatform/pelican/param"
log "github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
)

func DirectorServe(ctx context.Context, engine *gin.Engine, egrp *errgroup.Group) error {
Expand Down
2 changes: 1 addition & 1 deletion launchers/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func LaunchModules(ctx context.Context, modules config.ServerType) (context.Canc

if modules.IsEnabled(config.DirectorType) {

viper.Set("Director.DefaultResponse", "cache")
viper.Set("Director.DefaultResponse", param.Director_DefaultResponse.GetString())

viper.Set("Federation.DirectorURL", param.Server_ExternalWebUrl.GetString())

Expand Down

0 comments on commit 2764b38

Please sign in to comment.