Skip to content

Commit

Permalink
linksharing: eliminate path-specific optimization for hosted domains
Browse files Browse the repository at this point in the history
Change-Id: If3d3a335b6ac9b814c5d6e9d14500cbe29eecbee
  • Loading branch information
jtolio committed Jul 22, 2024
1 parent 82d843c commit 153c70f
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions pkg/linksharing/sharing/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,25 @@ func credentialsFromContext(ctx context.Context) *credentials {
// CredentialsHandler retrieves and saves credentials as a context value.
func (h *Handler) CredentialsHandler(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
path := strings.TrimPrefix(r.URL.Path, "/")

// don't try and get credentials for requests that don't need them.
if strings.HasPrefix(path, "static/") || strings.HasPrefix(path, "health/process") {
next.ServeHTTP(w, r)
return
}

var err error
var creds credentials
ctx := r.Context()
defer mon.TaskNamed("CredentialsHandler")(&ctx)(&err)

var creds credentials
ourDomain, err := isDomainOurs(r.Host, h.urlBases)
if err != nil {
creds.err = err
next.ServeHTTP(w, reqWithCredentials(ctx, r, &creds))
return
}

path := strings.TrimPrefix(r.URL.Path, "/")
// don't try and get credentials for requests that don't need them.
if ourDomain && (strings.HasPrefix(path, "static/") || strings.HasPrefix(path, "health/process")) {
next.ServeHTTP(w, r)
return
}

if ourDomain {
if path == "" {
next.ServeHTTP(w, r)
Expand Down

0 comments on commit 153c70f

Please sign in to comment.