示例#1
0
文件: http.js 项目: ericgj/resource
Service.prototype.options = function(parse,handle){
  var req = new request.Request('OPTIONS', this.target)
  applyOptions.call(this,req);
  req.end( 
    function(res){
      handle(res);
      parse(res);
    }
  );
}
示例#2
0
 _.defer(function () {
     request.end(function (response) {
         if (response.ok) {
             pending.resolve(response);
         }
         else {
             pending.reject(response);
         }
     });
 });
示例#3
0
function TwAgent(method, path) {
  var url = path.indexOf('http') === 0
    ? path
    : path[0] === '/'
      ? rootUrl + path
      : rootUrl + '/' + path;

  Request.call(this, method, url);
  this._oauthParams = {};
  this._params = {};
  this.oauth('signature_method', 'HMAC-SHA1');
  this.oauth('version', '1.0' );
}
示例#4
0
Ajax = function (url, options) {
    var pending = Promise.pending(),
        promise = pending.promise,
        method  = options.method,
        request = new Request(method, url),
        headers = options.headers,
        data    = options.data,
        header;
    if (headers != null) {
        for (header in headers) {
            if (headers.hasOwnProperty(header)) {
                request.set(header, headers[header]);
            }
        }
    }
    if (data != null) {
        if (method === 'POST' || method === 'PUT' || method === 'PATCH') {
            request.send(data);
        }
        else {
            request.query(data);
        }
    }
    promise.request = request;
    _.defer(function () {
        request.end(function (response) {
            if (response.ok) {
                pending.resolve(response);
            }
            else {
                pending.reject(response);
            }
        });
    });
    return pending.promise;
};
示例#5
0
 /**
  * Request object similar to superagent.Request, but with end() returning
  * a promise.
  */
 function PromiseRequest() {
   superagent.Request.apply(this, arguments);
 }