Skip to content

Commit dd278d3

Browse files
Updated the setRequestHeader to be directly testable and updated the tests to match the behavior set in the test-headers.js file
1 parent dd2a0c2 commit dd278d3

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/XMLHttpRequest.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ exports.XMLHttpRequest = function() {
111111
this.responseXML = "";
112112
this.status = null;
113113
this.statusText = null;
114-
114+
115115
// Whether cross-site Access-Control requests should be made using
116116
// credentials such as cookies or authorization headers
117117
this.withCredentials = false;
@@ -195,14 +195,15 @@ exports.XMLHttpRequest = function() {
195195
}
196196
if (!isAllowedHttpHeader(header)) {
197197
console.warn("Refused to set unsafe header \"" + header + "\"");
198-
return;
198+
return false;
199199
}
200200
if (sendFlag) {
201201
throw new Error("INVALID_STATE_ERR: send flag is true");
202202
}
203203
header = headersCase[header.toLowerCase()] || header;
204204
headersCase[header.toLowerCase()] = header;
205205
headers[header] = headers[header] ? headers[header] + ', ' + value : value;
206+
return true;
206207
};
207208

208209
/**

tests/test-exceptions.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,14 @@ var forbiddenRequestHeaders = [
4444
"trailer",
4545
"transfer-encoding",
4646
"upgrade",
47-
"user-agent",
4847
"via"
4948
];
5049

5150
for (var i in forbiddenRequestHeaders) {
5251
try {
53-
xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test");
54-
console.log("ERROR: " + forbiddenRequestHeaders[i] + " should have thrown exception");
52+
assert.equal(xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test"), false);
5553
} catch(e) {
54+
console.log("ERROR: Exception raised", e);
5655
}
5756
}
5857

0 commit comments

Comments
 (0)