@@ -56,7 +56,7 @@ func (q *Querier) GetQuerierAPIVersion() (string, error) {
5656 if querierAPIVersion != "" {
5757 return querierAPIVersion , nil
5858 }
59- response , err := q .sendRequestHelper (NormalisedURLPath {value : "/apiversion" }, func (url string ) (* http.Response , error ) {
59+ response , _ , err := q .sendRequestHelper (NormalisedURLPath {value : "/apiversion" }, func (url string ) (* http.Response , error ) {
6060 req , err := http .NewRequest ("GET" , url , nil )
6161 if err != nil {
6262 return nil , err
@@ -117,7 +117,7 @@ func (q *Querier) SendPostRequest(path string, data map[string]interface{}) (map
117117 if err != nil {
118118 return nil , err
119119 }
120- return q .sendRequestHelper (nP , func (url string ) (* http.Response , error ) {
120+ resp , _ , err := q .sendRequestHelper (nP , func (url string ) (* http.Response , error ) {
121121 if data == nil {
122122 data = map [string ]interface {}{}
123123 }
@@ -147,14 +147,15 @@ func (q *Querier) SendPostRequest(path string, data map[string]interface{}) (map
147147 client := & http.Client {}
148148 return client .Do (req )
149149 }, len (QuerierHosts ), nil )
150+ return resp , err
150151}
151152
152153func (q * Querier ) SendDeleteRequest (path string , data map [string ]interface {}, params map [string ]string ) (map [string ]interface {}, error ) {
153154 nP , err := NewNormalisedURLPath (path )
154155 if err != nil {
155156 return nil , err
156157 }
157- return q .sendRequestHelper (nP , func (url string ) (* http.Response , error ) {
158+ resp , _ , err := q .sendRequestHelper (nP , func (url string ) (* http.Response , error ) {
158159 jsonData , err := json .Marshal (data )
159160 if err != nil {
160161 return nil , err
@@ -188,13 +189,51 @@ func (q *Querier) SendDeleteRequest(path string, data map[string]interface{}, pa
188189 client := & http.Client {}
189190 return client .Do (req )
190191 }, len (QuerierHosts ), nil )
192+ return resp , err
191193}
192194
193195func (q * Querier ) SendGetRequest (path string , params map [string ]string ) (map [string ]interface {}, error ) {
194196 nP , err := NewNormalisedURLPath (path )
195197 if err != nil {
196198 return nil , err
197199 }
200+ resp , _ , err := q .sendRequestHelper (nP , func (url string ) (* http.Response , error ) {
201+ req , err := http .NewRequest ("GET" , url , nil )
202+ if err != nil {
203+ return nil , err
204+ }
205+
206+ query := req .URL .Query ()
207+
208+ for k , v := range params {
209+ query .Add (k , v )
210+ }
211+ req .URL .RawQuery = query .Encode ()
212+
213+ apiVerion , querierAPIVersionError := q .GetQuerierAPIVersion ()
214+ if querierAPIVersionError != nil {
215+ return nil , querierAPIVersionError
216+ }
217+ req .Header .Set ("cdi-version" , apiVerion )
218+ if QuerierAPIKey != nil {
219+ req .Header .Set ("api-key" , * QuerierAPIKey )
220+ }
221+ if nP .IsARecipePath () && q .RIDToCore != "" {
222+ req .Header .Set ("rid" , q .RIDToCore )
223+ }
224+
225+ client := & http.Client {}
226+ return client .Do (req )
227+ }, len (QuerierHosts ), nil )
228+ return resp , err
229+ }
230+
231+ func (q * Querier ) SendGetRequestWithResponseHeaders (path string , params map [string ]string ) (map [string ]interface {}, http.Header , error ) {
232+ nP , err := NewNormalisedURLPath (path )
233+ if err != nil {
234+ return nil , nil , err
235+ }
236+
198237 return q .sendRequestHelper (nP , func (url string ) (* http.Response , error ) {
199238 req , err := http .NewRequest ("GET" , url , nil )
200239 if err != nil {
@@ -230,7 +269,7 @@ func (q *Querier) SendPutRequest(path string, data map[string]interface{}) (map[
230269 if err != nil {
231270 return nil , err
232271 }
233- return q .sendRequestHelper (nP , func (url string ) (* http.Response , error ) {
272+ resp , _ , err := q .sendRequestHelper (nP , func (url string ) (* http.Response , error ) {
234273 jsonData , err := json .Marshal (data )
235274 if err != nil {
236275 return nil , err
@@ -257,6 +296,7 @@ func (q *Querier) SendPutRequest(path string, data map[string]interface{}) (map[
257296 client := & http.Client {}
258297 return client .Do (req )
259298 }, len (QuerierHosts ), nil )
299+ return resp , err
260300}
261301
262302type httpRequestFunction func (url string ) (* http.Response , error )
@@ -279,9 +319,9 @@ func GetAllCoreUrlsForPath(path string) []string {
279319 return result
280320}
281321
282- func (q * Querier ) sendRequestHelper (path NormalisedURLPath , httpRequest httpRequestFunction , numberOfTries int , retryInfoMap * map [string ]int ) (map [string ]interface {}, error ) {
322+ func (q * Querier ) sendRequestHelper (path NormalisedURLPath , httpRequest httpRequestFunction , numberOfTries int , retryInfoMap * map [string ]int ) (map [string ]interface {}, http. Header , error ) {
283323 if numberOfTries == 0 {
284- return nil , errors .New ("no SuperTokens core available to query" )
324+ return nil , nil , errors .New ("no SuperTokens core available to query" )
285325 }
286326
287327 querierHostLock .Lock ()
@@ -316,14 +356,14 @@ func (q *Querier) sendRequestHelper(path NormalisedURLPath, httpRequest httpRequ
316356 if resp != nil {
317357 resp .Body .Close ()
318358 }
319- return nil , err
359+ return nil , nil , err
320360 }
321361
322362 defer resp .Body .Close ()
323363
324364 body , readErr := ioutil .ReadAll (resp .Body )
325365 if readErr != nil {
326- return nil , readErr
366+ return nil , nil , readErr
327367 }
328368 if resp .StatusCode != 200 {
329369 if resp .StatusCode == RateLimitStatusCode {
@@ -341,17 +381,18 @@ func (q *Querier) sendRequestHelper(path NormalisedURLPath, httpRequest httpRequ
341381 }
342382 }
343383
344- return nil , fmt .Errorf ("SuperTokens core threw an error for a request to path: '%s' with status code: %v and message: %s" , path .GetAsStringDangerous (), resp .StatusCode , body )
384+ return nil , nil , fmt .Errorf ("SuperTokens core threw an error for a request to path: '%s' with status code: %v and message: %s" , path .GetAsStringDangerous (), resp .StatusCode , body )
345385 }
346386
387+ headers := resp .Header .Clone ()
347388 finalResult := make (map [string ]interface {})
348389 jsonError := json .Unmarshal (body , & finalResult )
349390 if jsonError != nil {
350391 return map [string ]interface {}{
351392 "result" : string (body ),
352- }, nil
393+ }, headers , nil
353394 }
354- return finalResult , nil
395+ return finalResult , headers , nil
355396}
356397
357398func ResetQuerierForTest () {
0 commit comments