From bb892b5f01b1124ca4d3344f632d7908a24e7334 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 18 May 2021 17:09:25 +0100 Subject: [PATCH] fix url proxy --- url/proxy/proxy.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/url/proxy/proxy.go b/url/proxy/proxy.go index 00e0e6a..896f174 100644 --- a/url/proxy/proxy.go +++ b/url/proxy/proxy.go @@ -40,13 +40,11 @@ func Handler(w http.ResponseWriter, r *http.Request) { Path: r.URL.Path, } - header := make(http.Header) apiURL := APIHost + "/url/proxy" // use /v1/ if len(APIKey) > 0 { apiURL = APIHost + "/v1/url/proxy" - header.Set("Authorization", "Bearer "+APIKey) } // make new request @@ -55,6 +53,16 @@ func Handler(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), 500) return } + + if req.Header == nil { + req.Header = make(http.Header) + } + + // set the api key after we're given the header + if len(APIKey) > 0 { + req.Header.Set("Authorization", "Bearer "+APIKey) + } + // call the backend for the url rsp, err := http.DefaultClient.Do(req) if err != nil {