Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

test-redirect-307.js 1.0KB

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