github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/rpc/client/headers.go (about)

     1  package client
     2  
     3  import (
     4  	"context"
     5  	"net/http"
     6  
     7  	"github.com/twitchtv/twirp"
     8  
     9  	"github.com/devseccon/trivy/pkg/log"
    10  )
    11  
    12  // WithCustomHeaders adds custom headers to request headers
    13  func WithCustomHeaders(ctx context.Context, customHeaders http.Header) context.Context {
    14  	// Attach the headers to a context
    15  	ctxWithToken, err := twirp.WithHTTPRequestHeaders(ctx, customHeaders)
    16  	if err != nil {
    17  		log.Logger.Warnf("twirp error setting headers: %s", err)
    18  		return ctx
    19  	}
    20  	return ctxWithToken
    21  }