twitst4tz

twitter statistics web application
Log | Files | Refs | README | LICENSE

test-redirect-302.js (1028B)


      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(302, {'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.getRequestHeader('Location'), '');
     31     assert.equal(xhr.responseText, "Hello World");
     32     sys.puts("done");
     33   }
     34 };
     35 
     36 try {
     37   xhr.open("GET", "http://localhost:8000/redirectingResource");
     38   xhr.send();
     39 } catch(e) {
     40   console.log("ERROR: Exception raised", e);
     41 }