You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.4 KiB

  1. var sys = require("util")
  2. , assert = require("assert")
  3. , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
  4. , xhr = new XMLHttpRequest();
  5. // Test request methods that aren't allowed
  6. try {
  7. xhr.open("TRACK", "http://localhost:8000/");
  8. console.log("ERROR: TRACK should have thrown exception");
  9. } catch(e) {}
  10. try {
  11. xhr.open("TRACE", "http://localhost:8000/");
  12. console.log("ERROR: TRACE should have thrown exception");
  13. } catch(e) {}
  14. try {
  15. xhr.open("CONNECT", "http://localhost:8000/");
  16. console.log("ERROR: CONNECT should have thrown exception");
  17. } catch(e) {}
  18. // Test valid request method
  19. try {
  20. xhr.open("GET", "http://localhost:8000/");
  21. } catch(e) {
  22. console.log("ERROR: Invalid exception for GET", e);
  23. }
  24. // Test forbidden headers
  25. var forbiddenRequestHeaders = [
  26. "accept-charset",
  27. "accept-encoding",
  28. "access-control-request-headers",
  29. "access-control-request-method",
  30. "connection",
  31. "content-length",
  32. "content-transfer-encoding",
  33. "cookie",
  34. "cookie2",
  35. "date",
  36. "expect",
  37. "host",
  38. "keep-alive",
  39. "origin",
  40. "referer",
  41. "te",
  42. "trailer",
  43. "transfer-encoding",
  44. "upgrade",
  45. "user-agent",
  46. "via"
  47. ];
  48. for (var i in forbiddenRequestHeaders) {
  49. try {
  50. xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test");
  51. console.log("ERROR: " + forbiddenRequestHeaders[i] + " should have thrown exception");
  52. } catch(e) {
  53. }
  54. }
  55. // Try valid header
  56. xhr.setRequestHeader("X-Foobar", "Test");
  57. console.log("Done");