aboutsummaryrefslogtreecommitdiffhomepage
path: root/node_modules/xmlhttprequest-ssl/tests/test-headers.js
diff options
context:
space:
mode:
authorYaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx>2017-11-29 11:44:34 +0300
committerYaroslav De La Peña Smirnov <yaros.rus_89@live.com.mx>2017-11-29 11:44:34 +0300
commit67fdec20726e48ba3a934cb25bb30d47ec4a4f29 (patch)
tree37fd9f4f0b0c20103e1646fc83021e4765de3680 /node_modules/xmlhttprequest-ssl/tests/test-headers.js
downloadspanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.tar.gz
spanish-checkers-67fdec20726e48ba3a934cb25bb30d47ec4a4f29.zip
Initial commit, version 0.5.3
Diffstat (limited to 'node_modules/xmlhttprequest-ssl/tests/test-headers.js')
-rw-r--r--node_modules/xmlhttprequest-ssl/tests/test-headers.js76
1 files changed, 76 insertions, 0 deletions
diff --git a/node_modules/xmlhttprequest-ssl/tests/test-headers.js b/node_modules/xmlhttprequest-ssl/tests/test-headers.js
new file mode 100644
index 0000000..76454f1
--- /dev/null
+++ b/node_modules/xmlhttprequest-ssl/tests/test-headers.js
@@ -0,0 +1,76 @@
+var sys = require("util")
+ , assert = require("assert")
+ , XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest
+ , xhr = new XMLHttpRequest()
+ , http = require("http");
+
+// Test server
+var server = http.createServer(function (req, res) {
+ // Test setRequestHeader
+ assert.equal("Foobar", req.headers["x-test"]);
+ // Test non-conforming allowed header
+ assert.equal("node-XMLHttpRequest-test", req.headers["user-agent"]);
+ // Test header set with blacklist disabled
+ assert.equal("http://github.com", req.headers["referer"]);
+
+ var body = "Hello World";
+ res.writeHead(200, {
+ "Content-Type": "text/plain",
+ "Content-Length": Buffer.byteLength(body),
+ // Set cookie headers to see if they're correctly suppressed
+ // Actual values don't matter
+ "Set-Cookie": "foo=bar",
+ "Set-Cookie2": "bar=baz",
+ "Date": "Thu, 30 Aug 2012 18:17:53 GMT",
+ "Connection": "close"
+ });
+ res.write("Hello World");
+ res.end();
+
+ this.close();
+}).listen(8000);
+
+xhr.onreadystatechange = function() {
+ if (this.readyState == 4) {
+ // Test getAllResponseHeaders()
+ var headers = "content-type: text/plain\r\ncontent-length: 11\r\ndate: Thu, 30 Aug 2012 18:17:53 GMT\r\nconnection: close";
+ assert.equal(headers, this.getAllResponseHeaders());
+
+ // Test case insensitivity
+ assert.equal('text/plain', this.getResponseHeader('Content-Type'));
+ assert.equal('text/plain', this.getResponseHeader('Content-type'));
+ assert.equal('text/plain', this.getResponseHeader('content-Type'));
+ assert.equal('text/plain', this.getResponseHeader('content-type'));
+
+ // Test aborted getAllResponseHeaders
+ this.abort();
+ assert.equal("", this.getAllResponseHeaders());
+ assert.equal(null, this.getResponseHeader("Connection"));
+
+ sys.puts("done");
+ }
+};
+
+assert.equal(null, xhr.getResponseHeader("Content-Type"));
+try {
+ xhr.open("GET", "http://localhost:8000/");
+ // Valid header
+ xhr.setRequestHeader("X-Test", "Foobar");
+ // Invalid header
+ xhr.setRequestHeader("Content-Length", 0);
+ // Allowed header outside of specs
+ xhr.setRequestHeader("user-agent", "node-XMLHttpRequest-test");
+ // Test getRequestHeader
+ assert.equal("Foobar", xhr.getRequestHeader("X-Test"));
+ // Test invalid header
+ assert.equal("", xhr.getRequestHeader("Content-Length"));
+
+ // Test allowing all headers
+ xhr.setDisableHeaderCheck(true);
+ xhr.setRequestHeader("Referer", "http://github.com");
+ assert.equal("http://github.com", xhr.getRequestHeader("Referer"));
+
+ xhr.send();
+} catch(e) {
+ console.log("ERROR: Exception raised", e);
+}