From 895319d35ef95cd59dc009325aa939b5344cfbf7 Mon Sep 17 00:00:00 2001 From: Austin DeNoble Date: Sun, 16 Jun 2024 13:53:38 -0400 Subject: [PATCH] add helper function for manipulating headers for outgoing requests - supports applying specific headers necessary for assistants routes when using OAuth --- internal/pkg/utils/network/request.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/pkg/utils/network/request.go b/internal/pkg/utils/network/request.go index 0f11e71..8783ec5 100644 --- a/internal/pkg/utils/network/request.go +++ b/internal/pkg/utils/network/request.go @@ -40,12 +40,24 @@ func buildRequest(verb string, path string, bodyJson []byte) (*http.Request, err } } + applyHeaders(req, path) + + return req, nil +} + +func applyHeaders(req *http.Request, url string) { + // request-specific headers + if strings.Contains(url, "assistant") { + req.Header.Set("X-Project-Id", state.TargetProj.Get().Id) + } + if strings.Contains(url, "chat/completions") { + req.Header.Set("X-Disable-Bearer-Auth", "true") + } + + // apply to all requests req.Header.Add("User-Agent", "Pinecone CLI") req.Header.Set("Content-Type", "application/json") - req.Header.Set("X-Project-Id", state.TargetProj.Get().Id) - req.Header.Set("X-Disable-Bearer-Auth", "true") - return req, nil } func performRequest(req *http.Request) (*http.Response, error) {