提交 adc251ca 编写于 作者: T Tim Schaub

Accept array in Headers constructor

上级 49e80307
......@@ -84,7 +84,10 @@
headers.forEach(function(value, name) {
this.append(name, value)
}, this)
} else if (Array.isArray(headers)) {
headers.forEach(function(header) {
this.append(header[0], header[1]);
}, this);
} else if (headers) {
Object.getOwnPropertyNames(headers).forEach(function(name) {
this.append(name, headers[name])
......
......@@ -170,6 +170,16 @@ suite('Headers', function() {
assert.equal(headers.get('Accept'), 'application/json,text/plain')
assert.equal(headers.get('Content-type'), 'text/html')
})
test('constructor works with arrays', function() {
var array = [
['Content-Type', 'text/xml'],
['Breaking-Bad', '<3']
];
var headers = new Headers(array)
assert.equal(headers.get('Content-Type'), 'text/xml')
assert.equal(headers.get('Breaking-Bad'), '<3')
})
test('headers are case insensitive', function() {
var headers = new Headers({'Accept': 'application/json'})
assert.equal(headers.get('ACCEPT'), 'application/json')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册