Comparing version 6.8.1 to 6.9.0
@@ -178,18 +178,24 @@ var foldHeaderLine = require('./foldHeaderLine'), | ||
Headers.prototype.set = function (headerName, valueOrValues, valueNumber) { | ||
var headerNameLowerCase = headerName.toLowerCase(); | ||
if (Array.isArray(valueOrValues)) { | ||
if (typeof valueNumber !== 'undefined') { | ||
throw new Error('Headers.set: valueNumber not supported when the values are provided as an array'); | ||
} | ||
if (valueOrValues.length === 0) { | ||
delete this.valuesByName[headerNameLowerCase]; | ||
if (headerName && typeof headerName === 'object') { | ||
Object.keys(headerName).forEach(function (key) { | ||
this.set(key, headerName[key]); | ||
}, this); | ||
} else { | ||
var headerNameLowerCase = headerName.toLowerCase(); | ||
if (Array.isArray(valueOrValues)) { | ||
if (typeof valueNumber !== 'undefined') { | ||
throw new Error('Headers.set: valueNumber not supported when the values are provided as an array'); | ||
} | ||
if (valueOrValues.length === 0) { | ||
delete this.valuesByName[headerNameLowerCase]; | ||
} else { | ||
this.valuesByName[headerNameLowerCase] = valueOrValues.map(function (value) { | ||
return this.parseHeaderValue(value); | ||
}, this); | ||
} | ||
} else if (typeof valueNumber === 'number' && Array.isArray(this.valuesByName[headerNameLowerCase]) && valueNumber < this.valuesByName[headerNameLowerCase].length) { | ||
this.valuesByName[headerNameLowerCase][valueNumber] = this.parseHeaderValue(valueOrValues); | ||
} else { | ||
this.valuesByName[headerNameLowerCase] = valueOrValues.map(function (value) { | ||
return this.parseHeaderValue(value); | ||
}, this); | ||
(this.valuesByName[headerNameLowerCase] = this.valuesByName[headerNameLowerCase] || []).push(this.parseHeaderValue(valueOrValues)); | ||
} | ||
} else if (typeof valueNumber === 'number' && Array.isArray(this.valuesByName[headerNameLowerCase]) && valueNumber < this.valuesByName[headerNameLowerCase].length) { | ||
this.valuesByName[headerNameLowerCase][valueNumber] = this.parseHeaderValue(valueOrValues); | ||
} else { | ||
(this.valuesByName[headerNameLowerCase] = this.valuesByName[headerNameLowerCase] || []).push(this.parseHeaderValue(valueOrValues)); | ||
} | ||
@@ -196,0 +202,0 @@ }; |
{ | ||
"name": "messy", | ||
"version": "6.8.1", | ||
"version": "6.9.0", | ||
"description": "Object model for HTTP and RFC822 messages", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -149,2 +149,14 @@ /*global describe, it*/ | ||
}); | ||
describe('when passed an object', function () { | ||
it('should act as a shorthand for calling set with each (key, value)', function () { | ||
var headers = new Headers({foo: 'bar', baz: 'quux'}); | ||
headers.set({ | ||
foo: [ 'bar2' ], | ||
baz: 'quux2', | ||
yadda: 'blah' | ||
}); | ||
expect(headers.toString(), 'to equal', 'Foo: bar2\r\nBaz: quux\r\nBaz: quux2\r\nYadda: blah\r\n'); | ||
}); | ||
}); | ||
}); | ||
@@ -151,0 +163,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
174691
3684