Comparing version 0.1.0 to 0.2.0
@@ -91,3 +91,3 @@ // Load modules | ||
internals.Error.unauthorized = function (error, scheme, attributes) { | ||
internals.Error.unauthorized = function (error, scheme, attributes) { // Or function (error, wwwAuthenticate[]) | ||
@@ -100,28 +100,48 @@ var err = new internals.Error(401, error); | ||
var wwwAuthenticate = scheme; | ||
if (attributes) { | ||
var names = Object.keys(attributes); | ||
for (var i = 0, il = names.length; i < il; ++i) { | ||
if (i) { | ||
wwwAuthenticate += ','; | ||
} | ||
var wwwAuthenticate = ''; | ||
var value = attributes[names[i]]; | ||
if (value === null || | ||
value === undefined) { // Value can be zero | ||
if (typeof scheme === 'string') { | ||
value = ''; | ||
// function (error, scheme, attributes) | ||
wwwAuthenticate = scheme; | ||
if (attributes) { | ||
var names = Object.keys(attributes); | ||
for (var i = 0, il = names.length; i < il; ++i) { | ||
if (i) { | ||
wwwAuthenticate += ','; | ||
} | ||
var value = attributes[names[i]]; | ||
if (value === null || | ||
value === undefined) { // Value can be zero | ||
value = ''; | ||
} | ||
wwwAuthenticate += ' ' + names[i] + '="' + Hoek.escapeHeaderAttribute(value.toString()) + '"'; | ||
} | ||
wwwAuthenticate += ' ' + names[i] + '="' + Hoek.escapeHeaderAttribute(value.toString()) + '"'; | ||
} | ||
} | ||
if (error) { | ||
if (attributes) { | ||
wwwAuthenticate += ','; | ||
if (error) { | ||
if (attributes) { | ||
wwwAuthenticate += ','; | ||
} | ||
wwwAuthenticate += ' error="' + Hoek.escapeHeaderAttribute(error) + '"'; | ||
} | ||
wwwAuthenticate += ' error="' + Hoek.escapeHeaderAttribute(error) + '"'; | ||
else { | ||
err.isMissing = true; | ||
} | ||
} | ||
else { | ||
err.isMissing = true; | ||
// function (error, wwwAuthenticate[]) | ||
var wwwArray = scheme; | ||
for (var i = 0, il = wwwArray.length; i < il; ++i) { | ||
if (i) { | ||
wwwAuthenticate += ', '; | ||
} | ||
wwwAuthenticate += wwwArray[i]; | ||
} | ||
} | ||
@@ -128,0 +148,0 @@ |
{ | ||
"name": "boom", | ||
"description": "HTTP-friendly error objects", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"author": "Eran Hammer <eran@hueniverse.com> (http://hueniverse.com)", | ||
@@ -6,0 +6,0 @@ "contributors": [], |
@@ -101,2 +101,9 @@ // Load modules | ||
}); | ||
it('sets a WWW-Authenticate when passed as an array', function (done) { | ||
var err = Boom.unauthorized('message', ['Basic', 'Example e="1"', 'Another x="3", y="4"']); | ||
expect(err.toResponse().headers['WWW-Authenticate']).to.equal('Basic, Example e="1", Another x="3", y="4"'); | ||
done(); | ||
}); | ||
}); | ||
@@ -103,0 +110,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15111
299