rob@77: var sys = require("util") rob@77: , assert = require("assert") rob@77: , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest rob@77: , xhr = new XMLHttpRequest(); rob@77: rob@77: // Test request methods that aren't allowed rob@77: try { rob@77: xhr.open("TRACK", "http://localhost:8000/"); rob@77: console.log("ERROR: TRACK should have thrown exception"); rob@77: } catch(e) {} rob@77: try { rob@77: xhr.open("TRACE", "http://localhost:8000/"); rob@77: console.log("ERROR: TRACE should have thrown exception"); rob@77: } catch(e) {} rob@77: try { rob@77: xhr.open("CONNECT", "http://localhost:8000/"); rob@77: console.log("ERROR: CONNECT should have thrown exception"); rob@77: } catch(e) {} rob@77: // Test valid request method rob@77: try { rob@77: xhr.open("GET", "http://localhost:8000/"); rob@77: } catch(e) { rob@77: console.log("ERROR: Invalid exception for GET", e); rob@77: } rob@77: rob@77: // Test forbidden headers rob@77: var forbiddenRequestHeaders = [ rob@77: "accept-charset", rob@77: "accept-encoding", rob@77: "access-control-request-headers", rob@77: "access-control-request-method", rob@77: "connection", rob@77: "content-length", rob@77: "content-transfer-encoding", rob@77: "cookie", rob@77: "cookie2", rob@77: "date", rob@77: "expect", rob@77: "host", rob@77: "keep-alive", rob@77: "origin", rob@77: "referer", rob@77: "te", rob@77: "trailer", rob@77: "transfer-encoding", rob@77: "upgrade", rob@77: "user-agent", rob@77: "via" rob@77: ]; rob@77: rob@77: for (var i in forbiddenRequestHeaders) { rob@77: try { rob@77: xhr.setRequestHeader(forbiddenRequestHeaders[i], "Test"); rob@77: console.log("ERROR: " + forbiddenRequestHeaders[i] + " should have thrown exception"); rob@77: } catch(e) { rob@77: } rob@77: } rob@77: rob@77: // Try valid header rob@77: xhr.setRequestHeader("X-Foobar", "Test"); rob@77: rob@77: console.log("Done");