add transporter_options

This commit is contained in:
Ming
2016-10-21 20:12:55 +08:00
parent e9ac552414
commit 48b7b75ac1
2 changed files with 9 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ var noop = require('lodash.noop');
var PemVerifier = require('./../pemverifier.js');
var querystring = require('querystring');
var util = require('util');
var DefaultTransporter = require('./../transporters.js');
var certificateCache = null;
var certificateExpiry = null;
@@ -35,7 +36,7 @@ var certificateExpiry = null;
* @param {Object} opt_opts optional options for overriding the given parameters.
* @constructor
*/
function OAuth2Client(clientId, clientSecret, redirectUri, opt_opts) {
function OAuth2Client(clientId, clientSecret, redirectUri, opt_opts, transporter_options) {
OAuth2Client.super_.call(this);
this.clientId_ = clientId;
@@ -43,6 +44,7 @@ function OAuth2Client(clientId, clientSecret, redirectUri, opt_opts) {
this.redirectUri_ = redirectUri;
this.opts = opt_opts || {};
this.credentials = {};
this.transporter = new DefaultTransporter(transporter_options);
}
/**
@@ -152,7 +154,7 @@ OAuth2Client.prototype.getToken = function(code, opt_callback) {
}
var done = opt_callback || noop;
done(err, tokens, response);
}, this.opts);
});
};
/**

View File

@@ -24,7 +24,9 @@ var utils = require('../lib/utils.js');
* Default transporter constructor.
* Wraps request and callback functions.
*/
function DefaultTransporter() {}
function DefaultTransporter(options) {
this.options = options || {};
}
/**
* Default user agent.
@@ -54,9 +56,9 @@ DefaultTransporter.prototype.configure = function(opts) {
* @param {Function=} opt_callback Optional callback.
* @return {Request} Request object
*/
DefaultTransporter.prototype.request = function(opts, opt_callback, extra_opts) {
DefaultTransporter.prototype.request = function(opts, opt_callback) {
opts = this.configure(opts);
opts = utils.extend(opts, extra_opts);
opts = utils.extend(opts, this.options);
return request(opts.uri || opts.url, opts, this.wrapCallback_(opt_callback));
};