[JavaScript] Handle custom request.agent (#6737)

* Handle custom request.agent

* better semantic
This commit is contained in:
kinok 2017-10-20 09:00:27 +02:00 committed by wing328
parent d0ec683a86
commit 649811d542
2 changed files with 21 additions and 0 deletions

View File

@ -91,6 +91,10 @@
this.agent = new superagent.agent(); this.agent = new superagent.agent();
} }
/*
* Allow user to override superagent agent
*/
this.requestAgent = null;
}; };
{{#emitJSDoc}} /** {{#emitJSDoc}} /**
@ -408,6 +412,12 @@
// set header parameters // set header parameters
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams)); 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 // set request timeout
request.timeout(this.timeout); request.timeout(this.timeout);

View File

@ -78,6 +78,12 @@ export default class ApiClient {
if (typeof window === 'undefined') { if (typeof window === 'undefined') {
this.agent = new superagent.agent(); this.agent = new superagent.agent();
} }
/*
* Allow user to override superagent agent
*/
this.requestAgent = null;
} }
{{#emitJSDoc}}/** {{#emitJSDoc}}/**
@ -396,6 +402,11 @@ export default class ApiClient {
// set header parameters // set header parameters
request.set(this.defaultHeaders).set(this.normalizeParams(headerParams)); 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 // set request timeout
request.timeout(this.timeout); request.timeout(this.timeout);