Skip to content

Commit

Permalink
Merge pull request JakeChampion#107 from kirill-konshin/master
Browse files Browse the repository at this point in the history
Headers constructor in Response constructor
  • Loading branch information
josh committed Mar 23, 2015
2 parents 8ccc0a2 + 89b4493 commit 654c94f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
this.status = options.status
this.ok = this.status >= 200 && this.status < 300
this.statusText = options.statusText
this.headers = options.headers
this.headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers)
this.url = options.url || ''
}

Expand Down
9 changes: 9 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ suite('Response', function() {
assert.equal(response.headers.get('Content-Type'), 'text/html; charset=utf-8')
})
})

test('creates Headers object from raw headers', function() {
var r = new Response('{"foo":"bar"}', {headers: {'content-type': 'application/json'}});
assert.equal(r.headers instanceof Headers, true);
return r.json().then(function(json){
assert(json.foo, 'bar');
return json;
})
})
})

// https://fetch.spec.whatwg.org/#body-mixin
Expand Down

0 comments on commit 654c94f

Please sign in to comment.