Skip to content
Myr

refactor to use basic-auth

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

authored by Jonathan Ong · committed by Jonathan Ong · parent b443da4 · Browse files · 3 files+22 added−21 removed
This commit

State

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

Diff stats

3 files+22 added−21 removed

  • tests:+8 added−2 removed
  • other:+14 added−19 removed

3 files+22 added−21 removed

modified:lib/request.js+13 added-19 removed
3 unmodified lines
4 */56var accepts = require('accepts');7var typeis = require('type-is');8var http = require('http')9 , utils = require('./utils')10 , fresh = require('fresh')11 , parseRange = require('range-parser')12 , parse = utils.parseUrl8var basicAuth = require('basic-auth');9var http = require('http');10var fresh = require('fresh');11var parseRange = require('range-parser');12var utils = require('./utils');13var parse = utils.parseUrl;1415/**16 * Request prototype.17 */
300 unmodified lines
318 * @api public319 */320321req.__defineGetter__('auth', function(){321 // missing322 var auth = this.get('Authorization');323 if (!auth) return;324325 // malformed326 var parts = auth.split(' ');327 if ('basic' != parts[0].toLowerCase()) return;328 if (!parts[1]) return;329 auth = parts[1];330331 // credentials332 auth = new Buffer(auth, 'base64').toString().match(/^([^:]*):(.*)$/);333 if (!auth) return;334 return { username: auth[1], password: auth[2] };322 var auth = basicAuth(this);323 if (auth) {324 // aliases for backwards compatibilty325 auth.username = auth.name;326 auth.password = auth.pass;327 }328 return auth;329});330331/**332 * Return subdomains as an array.
95 unmodified lines
modified:test/req.auth.js+8 added-2 removed
modified:package.json+1 added