Skip to content
Myr

Added `req.auth`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

tests to come

authored by TJ Holowaychuk · committed by TJ Holowaychuk · parent a934929 · Browse files · 1 file+27 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+27 added−0 removed

  • other:+27 added−0 removed

1 file+27 added−0 removed

modified:lib/request.js+27 added
367 unmodified lines
368 : [];369});370371/**372 * Return basic auth credentials.373 *374 * Examples:375 *376 * // http://tobi:hello@example.com377 * req.auth378 * // => { username: 'tobi', password: 'hello' }379 *380 * @return {Object}381 * @api public382 */383384req.__defineGetter__('auth', function(){385 // missing386 var auth = this.get('Authorization');387 if (!auth) return {};388389 // malformed390 auth = auth.split(' ')[1];391 if (!auth) return {};392393 // credentials394 auth = new Buffer(auth, 'base64').toString().split(':');395 return { username: auth[0], password: auth[1] };396});397398/**399 * Return subdomains as an array.400 *401 * For example "tobi.ferrets.example.com"402 * would provide `["ferrets", "tobi"]`.
82 unmodified lines