[SignalingServer] Optimize dependent modules
[platform/framework/web/wrtjs.git] / signaling_server / service / node_modules / xmlhttprequest-ssl / tests / test-redirect-307.js
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(307, {'Location': 'http://localhost:8000/'});
11     res.end();
12     return;
13   }
14
15   assert.equal(req.method, 'POST');
16
17   var body = "Hello World";
18   res.writeHead(200, {
19     "Content-Type": "text/plain",
20     "Content-Length": Buffer.byteLength(body),
21     "Date": "Thu, 30 Aug 2012 18:17:53 GMT",
22     "Connection": "close"
23   });
24   res.write("Hello World");
25   res.end();
26
27   this.close();
28 }).listen(8000);
29
30 xhr.onreadystatechange = function() {
31   if (this.readyState == 4) {
32     assert.equal(xhr.getRequestHeader('Location'), '');
33     assert.equal(xhr.responseText, "Hello World");
34     sys.puts("done");
35   }
36 };
37
38 try {
39   xhr.open("POST", "http://localhost:8000/redirectingResource");
40   xhr.send();
41 } catch(e) {
42   console.log("ERROR: Exception raised", e);
43 }