superagent
Advanced tools
Comparing version 0.10.0 to 0.11.0
;(function(){ | ||
/** | ||
* hasOwnProperty. | ||
*/ | ||
var has = Object.prototype.hasOwnProperty; | ||
/** | ||
* Require the given path. | ||
@@ -10,23 +18,28 @@ * | ||
function require(p, parent, orig){ | ||
var path = require.resolve(p) | ||
, mod = require.modules[path]; | ||
function require(path, parent, orig) { | ||
var resolved = require.resolve(path); | ||
// lookup failed | ||
if (null == path) { | ||
orig = orig || p; | ||
if (null == resolved) { | ||
orig = orig || path; | ||
parent = parent || 'root'; | ||
throw new Error('failed to require "' + orig + '" from "' + parent + '"'); | ||
var err = new Error('Failed to require "' + orig + '" from "' + parent + '"'); | ||
err.path = orig; | ||
err.parent = parent; | ||
err.require = true; | ||
throw err; | ||
} | ||
var module = require.modules[resolved]; | ||
// perform real require() | ||
// by invoking the module's | ||
// registered function | ||
if (!mod.exports) { | ||
mod.exports = {}; | ||
mod.client = mod.component = true; | ||
mod.call(this, mod, mod.exports, require.relative(path)); | ||
if (!module.exports) { | ||
module.exports = {}; | ||
module.client = module.component = true; | ||
module.call(this, module.exports, require.relative(resolved), module); | ||
} | ||
return mod.exports; | ||
return module.exports; | ||
} | ||
@@ -60,15 +73,22 @@ | ||
require.resolve = function(path){ | ||
var orig = path | ||
, reg = path + '.js' | ||
, regJSON = path + '.json' | ||
, index = path + '/index.js' | ||
, indexJSON = path + '/index.json'; | ||
require.resolve = function(path) { | ||
if (path.charAt(0) === '/') path = path.slice(1); | ||
var index = path + '/index.js'; | ||
return require.modules[reg] && reg | ||
|| require.modules[regJSON] && regJSON | ||
|| require.modules[index] && index | ||
|| require.modules[indexJSON] && indexJSON | ||
|| require.modules[orig] && orig | ||
|| require.aliases[index]; | ||
var paths = [ | ||
path, | ||
path + '.js', | ||
path + '.json', | ||
path + '/index.js', | ||
path + '/index.json' | ||
]; | ||
for (var i = 0; i < paths.length; i++) { | ||
var path = paths[i]; | ||
if (has.call(require.modules, path)) return path; | ||
} | ||
if (has.call(require.aliases, index)) { | ||
return require.aliases[index]; | ||
} | ||
}; | ||
@@ -105,11 +125,11 @@ | ||
/** | ||
* Register module at `path` with callback `fn`. | ||
* Register module at `path` with callback `definition`. | ||
* | ||
* @param {String} path | ||
* @param {Function} fn | ||
* @param {Function} definition | ||
* @api private | ||
*/ | ||
require.register = function(path, fn){ | ||
require.modules[path] = fn; | ||
require.register = function(path, definition) { | ||
require.modules[path] = definition; | ||
}; | ||
@@ -125,5 +145,6 @@ | ||
require.alias = function(from, to){ | ||
var fn = require.modules[from]; | ||
if (!fn) throw new Error('failed to alias "' + from + '", it does not exist'); | ||
require.alias = function(from, to) { | ||
if (!has.call(require.modules, from)) { | ||
throw new Error('Failed to alias "' + from + '", it does not exist'); | ||
} | ||
require.aliases[to] = from; | ||
@@ -147,3 +168,3 @@ }; | ||
function lastIndexOf(arr, obj){ | ||
function lastIndexOf(arr, obj) { | ||
var i = arr.length; | ||
@@ -160,6 +181,5 @@ while (i--) { | ||
function fn(path){ | ||
var orig = path; | ||
path = fn.resolve(path); | ||
return require(path, parent, orig); | ||
function localRequire(path) { | ||
var resolved = localRequire.resolve(path); | ||
return require(resolved, parent, path); | ||
} | ||
@@ -171,14 +191,15 @@ | ||
fn.resolve = function(path){ | ||
localRequire.resolve = function(path) { | ||
var c = path.charAt(0); | ||
if ('/' == c) return path.slice(1); | ||
if ('.' == c) return require.normalize(p, path); | ||
// resolve deps by returning | ||
// the dep in the nearest "deps" | ||
// directory | ||
if ('.' != path.charAt(0)) { | ||
var segs = parent.split('/'); | ||
var i = lastIndexOf(segs, 'deps') + 1; | ||
if (!i) i = 0; | ||
path = segs.slice(0, i + 1).join('/') + '/deps/' + path; | ||
return path; | ||
} | ||
return require.normalize(p, path); | ||
var segs = parent.split('/'); | ||
var i = lastIndexOf(segs, 'deps') + 1; | ||
if (!i) i = 0; | ||
path = segs.slice(0, i + 1).join('/') + '/deps/' + path; | ||
return path; | ||
}; | ||
@@ -190,8 +211,9 @@ | ||
fn.exists = function(path){ | ||
return !! require.modules[fn.resolve(path)]; | ||
localRequire.exists = function(path) { | ||
return has.call(require.modules, localRequire.resolve(path)); | ||
}; | ||
return fn; | ||
};require.register("component-emitter/index.js", function(module, exports, require){ | ||
return localRequire; | ||
}; | ||
require.register("component-emitter/index.js", function(exports, require, module){ | ||
@@ -346,9 +368,36 @@ /** | ||
}); | ||
require.register("superagent/lib/client.js", function(module, exports, require){ | ||
require.register("RedVentures-reduce/index.js", function(exports, require, module){ | ||
/** | ||
* Reduce `arr` with `fn`. | ||
* | ||
* @param {Array} arr | ||
* @param {Function} fn | ||
* @param {Mixed} initial | ||
* | ||
* TODO: combatible error handling? | ||
*/ | ||
module.exports = function(arr, fn, initial){ | ||
var idx = 0; | ||
var len = arr.length; | ||
var curr = arguments.length == 3 | ||
? initial | ||
: arr[idx++]; | ||
while (idx < len) { | ||
curr = fn.call(null, curr, arr[idx], ++idx, arr); | ||
} | ||
return curr; | ||
}; | ||
}); | ||
require.register("superagent/lib/client.js", function(exports, require, module){ | ||
/** | ||
* Module dependencies. | ||
*/ | ||
var Emitter = require('emitter'); | ||
var Emitter = require('emitter') | ||
, reduce = require('reduce'); | ||
@@ -557,3 +606,3 @@ /** | ||
function params(str){ | ||
return str.split(/ *; */).reduce(function(obj, str){ | ||
return reduce(str.split(/ *; */), function(obj, str){ | ||
var parts = str.split(/ *= */) | ||
@@ -697,3 +746,5 @@ , key = parts.shift() | ||
this.serverError = 5 == type; | ||
this.error = 4 == type || 5 == type; | ||
this.error = (4 == type || 5 == type) | ||
? this.toError() | ||
: false; | ||
@@ -747,3 +798,5 @@ // sugar | ||
this.on('end', function(){ | ||
self.callback(null, new Response(self.xhr)); | ||
var res = new Response(self.xhr); | ||
if ('HEAD' == method) res.text = null; | ||
self.callback(null, res); | ||
}); | ||
@@ -1181,11 +1234,16 @@ } | ||
module.exports = request; | ||
}); | ||
require.alias("component-emitter/index.js", "superagent/deps/emitter/index.js"); | ||
require.alias("RedVentures-reduce/index.js", "superagent/deps/reduce/index.js"); | ||
require.alias("superagent/lib/client.js", "superagent/index.js"); | ||
if ("undefined" == typeof module) { | ||
window.superagent = require("superagent"); | ||
} else { | ||
module.exports = require("superagent"); | ||
} | ||
})(); | ||
if (typeof exports == "object") { | ||
module.exports = require("superagent"); | ||
} else if (typeof define == "function" && define.amd) { | ||
define(require("superagent")); | ||
} else { | ||
window["superagent"] = require("superagent"); | ||
}})(); |
@@ -5,3 +5,3 @@ { | ||
"description": "awesome http requests", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"keywords": [ | ||
@@ -18,5 +18,6 @@ "http", | ||
"dependencies": { | ||
"component/emitter": "0.0.6" | ||
"component/emitter": "*", | ||
"RedVentures/reduce": "*" | ||
}, | ||
"license": "MIT" | ||
} | ||
} |
@@ -99,2 +99,17 @@ # SuperAgent | ||
## Dealing with errors | ||
On a network error (e.g. connection refused or timeout), SuperAgent emits | ||
`error` unless you pass `.end()` a callback with two parameters. Then | ||
SuperAgent will invoke it with the error first, followed by a null response. | ||
request | ||
.get('http://wrongurl') | ||
.end(function(err, res){ | ||
console.log('ERROR: ', err) | ||
}); | ||
On HTTP errors instead, SuperAgent populates the response with flags | ||
indicating the error. See `Response status` below. | ||
## Setting header fields | ||
@@ -205,2 +220,2 @@ | ||
res.notAcceptable = 406 == status; | ||
res.notFound = 404 == status; | ||
res.notFound = 404 == status; |
0.11.0 / 2013-01-02 | ||
================== | ||
* add .error Error object. Closes #156 | ||
* add forcing of res.text removal for FF HEAD responses. Closes #162 | ||
* add reduce component usage. Closes #90 | ||
* move better-assert dep to development deps | ||
0.10.0 / 2012-11-14 | ||
@@ -3,0 +11,0 @@ ================== |
@@ -6,3 +6,4 @@ | ||
var Emitter = require('emitter'); | ||
var Emitter = require('emitter') | ||
, reduce = require('reduce'); | ||
@@ -211,3 +212,3 @@ /** | ||
function params(str){ | ||
return str.split(/ *; */).reduce(function(obj, str){ | ||
return reduce(str.split(/ *; */), function(obj, str){ | ||
var parts = str.split(/ *= */) | ||
@@ -351,3 +352,5 @@ , key = parts.shift() | ||
this.serverError = 5 == type; | ||
this.error = 4 == type || 5 == type; | ||
this.error = (4 == type || 5 == type) | ||
? this.toError() | ||
: false; | ||
@@ -401,3 +404,5 @@ // sugar | ||
this.on('end', function(){ | ||
self.callback(null, new Response(self.xhr)); | ||
var res = new Response(self.xhr); | ||
if ('HEAD' == method) res.text = null; | ||
self.callback(null, res); | ||
}); | ||
@@ -834,2 +839,2 @@ } | ||
module.exports = request; | ||
module.exports = request; |
@@ -137,3 +137,5 @@ | ||
this.serverError = 5 == type; | ||
this.error = 4 == type || 5 == type; | ||
this.error = (4 == type || 5 == type) | ||
? this.toError() | ||
: false; | ||
@@ -140,0 +142,0 @@ // sugar |
{ | ||
"name": "superagent", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "elegant & feature rich browser / node HTTP with a fluent API", | ||
@@ -25,7 +25,7 @@ "keywords": [ | ||
"methods": "0.0.1", | ||
"cookiejar": "1.3.0", | ||
"better-assert": "~0.1.0" | ||
"cookiejar": "1.3.0" | ||
}, | ||
"devDependencies": { | ||
"express": "3.0.3", | ||
"better-assert": "~0.1.0", | ||
"should": "*", | ||
@@ -32,0 +32,0 @@ "mocha": "*" |
@@ -69,3 +69,3 @@ # SuperAgent | ||
$ npm install -d | ||
$ npm install | ||
@@ -80,3 +80,3 @@ Run em! | ||
$ npm install -d | ||
$ npm install | ||
@@ -89,17 +89,8 @@ Start the test server: | ||
## Persisting an agent (with cookies, ie sessions) | ||
## Browser build | ||
```js | ||
var request = require('superagent'); | ||
var user1 = request.agent(); | ||
user1 | ||
.post('http://localhost:4000/signin') | ||
.send({ user: 'hunter@hunterloftis.com', password: 'password' }) | ||
.end(function(err, res) { | ||
// user1 will manage its own cookies | ||
// res.redirects contains an Array of redirects | ||
}); | ||
``` | ||
The browser build of superagent is located in the `./build` directory. | ||
Examples: | ||
## Examples: | ||
- [agency tests](superagent/blob/master/test/node/agency.js) | ||
@@ -114,23 +105,2 @@ - [express demo app](https://github.com/hunterloftis/component-test/blob/master/lib/users/test/controller.test.js) | ||
(The MIT License) | ||
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca> | ||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
MIT |
Sorry, the diff of this file is not supported yet
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
92226
6
26
3151
4
103
- Removedbetter-assert@~0.1.0
- Removedbetter-assert@0.1.0(transitive)
- Removedcallsite@1.0.0(transitive)