Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// _postParams should initially be null instead of {} because we want to allow people to send POST requests with
// empty data sets (if they need to). This way, we can differentiate between a default of null, an empty data set,
// and a populated data set.
this._postParams = null;
this._headers = {};
this._timeout = null;
this._type = "json"; // superagent's default, only for POST/PUT/PATCH methods
// public field
this.aborted = undefined; //default to undefined
}
// we implement a subset of superagent's API. for the other methods,
// for now, we'll just throw an exception if they're called. By default,
// all methods throw exceptions, and we override some below
Object.keys(superagent.Request.prototype)
.forEach( propName => {
var originalProp = superagent.Request.prototype[propName];
if (typeof originalProp === 'function') {
Request.prototype[propName] = function () {
throw new Error(`${propName}() from superagent's API isn't implemented yet.`);
}
}
});
Request.prototype.agent = function (agent) {
if (typeof agent === 'undefined') {
return this._agent;
}
this._agent = agent;
return this;
}
it('should patch superagent', function (done) {
superagent.Request.prototype.end = function (fn) {
fn(null, {
status: 200
});
};
should(superagentPromisePlugin.patch(superagent)).equal(superagent);
superagent.get('/success')
.catch(function () {})
.then(function (res) {
should(res.status).equal(200);
done();
});
});
});
it('request method returns instanceof superagent', function () {
var req = request('').get('/');
req.should.be.instanceof(request.Test.super_);
if (isNode) {
req.should.be.instanceof(require('superagent').Request);
}
});
module.exports.request = function (app) {
if ('function' == typeof app) app = http.createServer(app);
var addr = app.address();
var portno = addr ? addr.port : port++;
if (!addr) app.listen(portno);
var protocol = app instanceof https.Server ? 'https' : 'http';
var host = protocol + '://127.0.0.1:' + portno;
request.Request = function (method, url) {
var newRequest =new Request(method, host + url);
newRequest.redirects(0);
return newRequest;
}
return request;
};
.then(function(data) {
expect(request.Request.prototype.proxy.calledWithMatch(proxy)).to.be.true;
done();
});
},
;(function() {
/**
* NPM module dependencies.
*/
var superagent = require('superagent')
, Request = superagent.Request;
/**
* Rereddit module definition.
*/
var rereddit = module.exports = {};
/**
* Rereddit helpers.
*/
var base_url = rereddit.base_url = 'http://www.reddit.com/';
var store = {};
var thing = rereddit.thing = {};
thing.regex = /t[0-9]+_[a-z0-9]+/g;
thing.types = {
PromiseRequest.prototype.end = function() {
var _super = superagent.Request.prototype.end;
var context = this;
return new Promise(function(accept, reject) {
_super.call(context, function(err, value) {
if (err) {
return reject(err);
}
accept(value);
});
});
};
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* TodoService
*/
var Promise = require('bluebird');
var superagent = require('superagent');
var Fluxy = require('fluxy');
/*
* monkey patch superagent to make it promise-able
*/
superagent.Request.prototype.promise = function () {
var token = Promise.defer();
this.end(function (err, res) {
if (err) { return token.reject(err); }
if (res.status !== 200) {
if (res.body && res.body.error) {
token.reject(res.body);
}
else {
token.reject(res.error);
}
}
else {
token.resolve(res.body);
}
});
return token.promise;
},{"./handlers/AppHandler.jsx":11,"./handlers/RepoHandler.jsx":12,"./handlers/SearchHandler.jsx":13,"react":"react","react-router":"react-router"}],17:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
var _superagent = require("superagent");
var Request = _superagent.Request;
var request = _interopRequire(_superagent);
Request.prototype.exec = function () {
var req = this;
return new Promise(function (resolve, reject) {
req.end(function (error, res) {
if (error) return reject(error);
resolve(res);
});
});
};
module.exports = request;
/**
* Module dependencies.
*/
var request = require('superagent');
var methods = require('./methods');
var protoMethods = Object.keys(request.Request.prototype);
/**
* Expose `Context`.
*/
module.exports = Context;
/**
* Initialize a new `Context`.
*
* @api public
*/
function Context(superagent) {
if (!(this instanceof Context)) return new Context(superagent);
this.request = superagent || request;