|
| 1 | +var sys = require("util") |
| 2 | + , assert = require("assert") |
| 3 | + , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest |
| 4 | + , xhr = new XMLHttpRequest() |
| 5 | + , http = require("http"); |
| 6 | + |
| 7 | +// Test server |
| 8 | +var server = http.createServer(function (req, res) { |
| 9 | + if (req.url === '/redirectingResource') { |
| 10 | + res.writeHead(301, {'Location': 'http://localhost:8000/'}); |
| 11 | + res.end(); |
| 12 | + return; |
| 13 | + } |
| 14 | + |
| 15 | + var body = "Hello World"; |
| 16 | + res.writeHead(200, { |
| 17 | + "Content-Type": "text/plain", |
| 18 | + "Content-Length": Buffer.byteLength(body), |
| 19 | + "Date": "Thu, 30 Aug 2012 18:17:53 GMT", |
| 20 | + "Connection": "close" |
| 21 | + }); |
| 22 | + res.write("Hello World"); |
| 23 | + res.end(); |
| 24 | + |
| 25 | + this.close(); |
| 26 | +}).listen(8000); |
| 27 | + |
| 28 | +xhr.onreadystatechange = function() { |
| 29 | + if (this.readyState == 4) { |
| 30 | + assert.equal(xhr.status, 200); |
| 31 | + assert.equal(xhr.getRequestHeader('Location'), ''); |
| 32 | + assert.equal(xhr.responseText, "Hello World"); |
| 33 | + sys.puts("done"); |
| 34 | + } |
| 35 | +}; |
| 36 | + |
| 37 | +try { |
| 38 | + xhr.open("GET", "http://localhost:8000/redirectingResource"); |
| 39 | + xhr.send(); |
| 40 | +} catch(e) { |
| 41 | + console.log("ERROR: Exception raised", e); |
| 42 | +} |
0 commit comments