Skip to content
This repository has been archived by the owner on Jan 26, 2023. It is now read-only.

Commit

Permalink
use an agent() to isolate credential requests
Browse files Browse the repository at this point in the history
ensure makeHTTPRequest does not use credentials and makeCredentialHTTPRequest does by using an agent() instead of the singleton from the require
  • Loading branch information
camallen committed Nov 22, 2019
1 parent fcc45af commit 05c66ef
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/make-http-request.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ normalizeUrl = require 'normalizeurl'

getsInProgress = {}

if request.agent?
request = request.agent()

# Superagent will only auto-parse responses from a Content-Type header it recognizes.
# Add the Accept in use by the JSON API spec, which is what will be sent back from the server.
request.parse ?= {}
request.parse[DEFAULT_HEADERS['Accept']] = JSON.parse.bind JSON

# isolate the credential requests from the superagent singleton
# via the agent() to ensure correct credentials for both request types
# http://visionmedia.github.io/superagent/#agents-for-global-state
if request.agent? && request.withCredentials?
credentialRequest = request.agent().withCredentials()

makeHTTPRequest = (method, url, data, headers = {}, query) ->
makeRequest(request, method, url, data, headers, query)

makeCredentialHTTPRequest = (method, url, data, headers = {}, query) ->
if request.withCredentials?
request = request.withCredentials()
makeRequest(request, method, url, data, headers, query)
makeRequest(credentialRequest, method, url, data, headers, query)

makeRequest = (request, method, url, data, headers, query) ->
originalArguments = Array::slice.call arguments # In case we need to retry
Expand Down

0 comments on commit 05c66ef

Please sign in to comment.