MCPcopy Create free account
hub / github.com/bricks-cloud/BricksLLM / rewriteHttpAuthHeader

Function rewriteHttpAuthHeader

internal/authenticator/authenticator.go:82–118  ·  view source on GitHub ↗
(req *http.Request, setting *provider.Setting)

Source from the content-addressed store, hash-verified

80}
81
82func rewriteHttpAuthHeader(req *http.Request, setting *provider.Setting) error {
83 uri := req.URL.RequestURI()
84 if strings.HasPrefix(uri, "/api/routes") {
85 return nil
86 }
87
88 apiKey := setting.GetParam("apikey")
89
90 if strings.HasPrefix(uri, "/api/providers/vllm") {
91 if len(apiKey) != 0 {
92 req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
93 }
94 return nil
95 }
96
97 if len(apiKey) == 0 {
98 if setting.Provider == "bedrock" {
99 return nil
100 }
101
102 return errors.New("api key is empty in provider setting")
103 }
104
105 if strings.HasPrefix(uri, "/api/providers/anthropic") {
106 req.Header.Set("x-api-key", apiKey)
107 return nil
108 }
109
110 if strings.HasPrefix(uri, "/api/providers/azure") {
111 req.Header.Set("api-key", apiKey)
112 return nil
113 }
114
115 req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", apiKey))
116
117 return nil
118}
119
120func (a *Authenticator) canKeyAccessCustomRoute(path string, keyId string) error {
121 trimed := strings.TrimPrefix(path, "/api/routes")

Callers 1

Calls 2

GetParamMethod · 0.80
SetMethod · 0.65

Tested by

no test coverage detected