Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added support for status code 303, tests for 302, 303, 307
- Loading branch information
Showing
4 changed files
with
130 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var sys = require("util") | ||
, assert = require("assert") | ||
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest | ||
, xhr = new XMLHttpRequest() | ||
, http = require("http"); | ||
|
||
// Test server | ||
var server = http.createServer(function (req, res) { | ||
|
||
if(req.url === '/redirectingResource'){ | ||
res.writeHead(302, {'Location': 'http://localhost:8000/'}) | ||
res.end() | ||
return | ||
} | ||
|
||
var body = "Hello World"; | ||
res.writeHead(200, { | ||
"Content-Type": "text/plain", | ||
"Content-Length": Buffer.byteLength(body), | ||
"Date": "Thu, 30 Aug 2012 18:17:53 GMT", | ||
"Connection": "close" | ||
}); | ||
res.write("Hello World"); | ||
res.end(); | ||
|
||
this.close(); | ||
}).listen(8000); | ||
|
||
xhr.onreadystatechange = function() { | ||
if (this.readyState == 4) { | ||
assert.equal(xhr.getRequestHeader('Location'), '') | ||
assert.equal(xhr.responseText, "Hello World") | ||
sys.puts("done"); | ||
} | ||
}; | ||
|
||
try { | ||
xhr.open("GET", "http://localhost:8000/redirectingResource"); | ||
xhr.send(); | ||
} catch(e) { | ||
console.log("ERROR: Exception raised", e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
var sys = require("util") | ||
, assert = require("assert") | ||
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest | ||
, xhr = new XMLHttpRequest() | ||
, http = require("http"); | ||
|
||
// Test server | ||
var server = http.createServer(function (req, res) { | ||
|
||
if(req.url === '/redirectingResource'){ | ||
res.writeHead(303, {'Location': 'http://localhost:8000/'}) | ||
res.end() | ||
return | ||
} | ||
|
||
var body = "Hello World"; | ||
res.writeHead(200, { | ||
"Content-Type": "text/plain", | ||
"Content-Length": Buffer.byteLength(body), | ||
"Date": "Thu, 30 Aug 2012 18:17:53 GMT", | ||
"Connection": "close" | ||
}); | ||
res.write("Hello World"); | ||
res.end(); | ||
|
||
this.close(); | ||
}).listen(8000); | ||
|
||
xhr.onreadystatechange = function() { | ||
if (this.readyState == 4) { | ||
assert.equal(xhr.getRequestHeader('Location'), '') | ||
assert.equal(xhr.responseText, "Hello World") | ||
sys.puts("done"); | ||
} | ||
}; | ||
|
||
try { | ||
xhr.open("POST", "http://localhost:8000/redirectingResource"); | ||
xhr.send(); | ||
} catch(e) { | ||
console.log("ERROR: Exception raised", e); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
var sys = require("util") | ||
, assert = require("assert") | ||
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest | ||
, xhr = new XMLHttpRequest() | ||
, http = require("http"); | ||
|
||
// Test server | ||
var server = http.createServer(function (req, res) { | ||
|
||
if(req.url === '/redirectingResource'){ | ||
res.writeHead(307, {'Location': 'http://localhost:8000/'}) | ||
res.end() | ||
return | ||
} | ||
|
||
assert.equal(req.method, 'POST') | ||
|
||
var body = "Hello World"; | ||
res.writeHead(200, { | ||
"Content-Type": "text/plain", | ||
"Content-Length": Buffer.byteLength(body), | ||
"Date": "Thu, 30 Aug 2012 18:17:53 GMT", | ||
"Connection": "close" | ||
}); | ||
res.write("Hello World"); | ||
res.end(); | ||
|
||
this.close(); | ||
}).listen(8000); | ||
|
||
xhr.onreadystatechange = function() { | ||
if (this.readyState == 4) { | ||
assert.equal(xhr.getRequestHeader('Location'), '') | ||
assert.equal(xhr.responseText, "Hello World") | ||
sys.puts("done"); | ||
} | ||
}; | ||
|
||
try { | ||
xhr.open("POST", "http://localhost:8000/redirectingResource"); | ||
xhr.send(); | ||
} catch(e) { | ||
console.log("ERROR: Exception raised", e); | ||
} |