Skip to content

Commit

Permalink
[JavaScript] Handle custom request.agent (#6737)
Browse files Browse the repository at this point in the history
* Handle custom request.agent

* better semantic
  • Loading branch information
kinok authored and wing328 committed Oct 20, 2017
1 parent d0ec683 commit 649811d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
this.agent = new superagent.agent();
}

/*
* Allow user to override superagent agent
*/
this.requestAgent = null;
};

{{#emitJSDoc}} /**
Expand Down Expand Up @@ -408,6 +412,12 @@
// set header parameters
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));


// set requestAgent if it is set by user
if (this.requestAgent) {
request.agent(this.requestAgent);
}

// set request timeout
request.timeout(this.timeout);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ export default class ApiClient {
if (typeof window === 'undefined') {
this.agent = new superagent.agent();
}

/*
* Allow user to override superagent agent
*/
this.requestAgent = null;

}

{{#emitJSDoc}}/**
Expand Down Expand Up @@ -396,6 +402,11 @@ export default class ApiClient {
// set header parameters
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams));

// set requestAgent if it is set by user
if (this.requestAgent) {
request.agent(this.requestAgent);
}

// set request timeout
request.timeout(this.timeout);

Expand Down

0 comments on commit 649811d

Please sign in to comment.