Skip to content

Commit d1f80c6

Browse files
committed
Add getRequestHeader method with test. Needs to be made case-insensitive.
1 parent c961687 commit d1f80c6

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/XMLHttpRequest.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,21 @@ exports.XMLHttpRequest = function() {
218218
return result.substr(0, result.length - 2);
219219
};
220220

221+
/**
222+
* Gets a request header
223+
*
224+
* @param string name Name of header to get
225+
* @return string Returns the request header or empty string if not set
226+
*/
227+
this.getRequestHeader = function(name) {
228+
// @TODO Make this case insensitive
229+
if (typeof name === "string" && headers[name]) {
230+
return headers[name];
231+
}
232+
233+
return "";
234+
}
235+
221236
/**
222237
* Sends the request to the server.
223238
*

tests/test-headers.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ assert.equal(null, xhr.getResponseHeader("Content-Type"));
5050
try {
5151
xhr.open("GET", "http://localhost:8000/");
5252
xhr.setRequestHeader("X-Test", "Foobar");
53+
// Test getRequestHeader
54+
assert.equal("Foobar", xhr.getRequestHeader("X-Test"));
5355
xhr.send();
5456
} catch(e) {
5557
console.log("ERROR: Exception raised", e);

0 commit comments

Comments
 (0)