Combine request headers with the same name

This commit is contained in:
slackersoft 2014-07-29 07:45:12 -07:00
parent 80af85b4cf
commit 0b2b4a4a2e
2 changed files with 11 additions and 1 deletions

View File

@ -185,7 +185,11 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
},
setRequestHeader: function(header, value) {
this.requestHeaders[header] = value;
if(this.requestHeaders.hasOwnProperty(header)) {
this.requestHeaders[header] = [this.requestHeaders[header], value].join(', ');
} else {
this.requestHeaders[header] = value;
}
},
abort: function() {

View File

@ -37,6 +37,12 @@ describe("FakeXMLHttpRequest", function() {
expect(xhr.requestHeaders['X-Header-1']).toEqual('one');
});
it('should combine request headers with the same header name', function() {
xhr.setRequestHeader('X-Header-1', 'two');
expect(objectKeys(xhr.requestHeaders).length).toEqual(1);
expect(xhr.requestHeaders['X-Header-1']).toEqual('one, two');
});
describe("when setting headers on another xhr object", function() {
beforeEach(function() {
xhr2.setRequestHeader('X-Header-2', 'two');