github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/pkg/assets/context.go (about)

     1  package assets
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  )
     7  
     8  type PublicPathPrefixContextKey struct{}
     9  
    10  func getPublicPathPrefix(r *http.Request) string {
    11  	val := r.Context().Value(PublicPathPrefixContextKey{})
    12  	s, _ := val.(string)
    13  	return s
    14  }
    15  
    16  func appendPublicPathPrefix(prefix string, r *http.Request) *http.Request {
    17  	key := PublicPathPrefixContextKey{}
    18  	existingPrefix := getPublicPathPrefix(r)
    19  	return r.WithContext(context.WithValue(r.Context(), key, existingPrefix+prefix))
    20  }