Skip to content

Commit 895319d

Browse files
add helper function for manipulating headers for outgoing requests - supports applying specific headers necessary for assistants routes when using OAuth
1 parent 584300a commit 895319d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

internal/pkg/utils/network/request.go

+15-3
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,24 @@ func buildRequest(verb string, path string, bodyJson []byte) (*http.Request, err
4040
}
4141
}
4242

43+
applyHeaders(req, path)
44+
45+
return req, nil
46+
}
47+
48+
func applyHeaders(req *http.Request, url string) {
49+
// request-specific headers
50+
if strings.Contains(url, "assistant") {
51+
req.Header.Set("X-Project-Id", state.TargetProj.Get().Id)
52+
}
53+
if strings.Contains(url, "chat/completions") {
54+
req.Header.Set("X-Disable-Bearer-Auth", "true")
55+
}
56+
57+
// apply to all requests
4358
req.Header.Add("User-Agent", "Pinecone CLI")
4459
req.Header.Set("Content-Type", "application/json")
45-
req.Header.Set("X-Project-Id", state.TargetProj.Get().Id)
46-
req.Header.Set("X-Disable-Bearer-Auth", "true")
4760

48-
return req, nil
4961
}
5062

5163
func performRequest(req *http.Request) (*http.Response, error) {

0 commit comments

Comments
 (0)