-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Made it so that you can send an argument to send that allows the user…
… to ignore an invalid certificate. This is so you can write apps to connect to self signed cert servers.
- Loading branch information
1 parent
e2ae9aa
commit df80728
Showing
3 changed files
with
135 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var sys = require("util") | ||
, assert = require("assert") | ||
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest | ||
, https = require("https") | ||
, fs = require('fs') | ||
, xhr; | ||
|
||
var options = { | ||
key: fs.readFileSync('key.pem'), | ||
cert: fs.readFileSync('cert.pem') | ||
}; | ||
|
||
// Test server | ||
var server = https.createServer(options, function (req, res) { | ||
// Check request method and URL | ||
assert.equal(methods[curMethod], req.method); | ||
assert.equal("/" + methods[curMethod], req.url); | ||
|
||
var body = (req.method != "HEAD" ? "Hello World" : ""); | ||
|
||
res.writeHead(200, { | ||
"Content-Type": "text/plain", | ||
"Content-Length": Buffer.byteLength(body) | ||
}); | ||
// HEAD has no body | ||
if (req.method != "HEAD") { | ||
res.write(body); | ||
} | ||
res.end(); | ||
|
||
if (curMethod == methods.length - 1) { | ||
this.close(); | ||
console.log("done"); | ||
} | ||
}).listen(8000); | ||
|
||
// Test standard methods | ||
var methods = ["GET", "POST", "HEAD", "PUT", "DELETE"]; | ||
var curMethod = 0; | ||
|
||
function start(method) { | ||
// Reset each time | ||
xhr = new XMLHttpRequest(); | ||
|
||
xhr.onreadystatechange = function() { | ||
if (this.readyState == 4) { | ||
if (method == "HEAD") { | ||
assert.equal("", this.responseText); | ||
} else { | ||
assert.equal("Hello World", this.responseText); | ||
} | ||
|
||
curMethod++; | ||
|
||
if (curMethod < methods.length) { | ||
console.log("Testing " + methods[curMethod]); | ||
start(methods[curMethod]); | ||
} | ||
} | ||
}; | ||
|
||
var url = "https://localhost:8000/" + method; | ||
xhr.open(method, url, true, 'foo', 'bar', false); | ||
xhr.send(); | ||
} | ||
|
||
console.log("Testing " + methods[curMethod]); | ||
start(methods[curMethod]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
var sys = require("util") | ||
, assert = require("assert") | ||
, XMLHttpRequest = require("../lib/XMLHttpRequest").XMLHttpRequest | ||
, https = require("https") | ||
, fs = require('fs') | ||
, xhr; | ||
|
||
var options = { | ||
key: fs.readFileSync('key.pem'), | ||
cert: fs.readFileSync('cert.pem') | ||
}; | ||
|
||
// Test server | ||
var server = https.createServer(options, function (req, res) { | ||
// Check request method and URL | ||
assert.equal(methods[curMethod], req.method); | ||
assert.equal("/" + methods[curMethod], req.url); | ||
|
||
var body = (req.method != "HEAD" ? "Hello World" : ""); | ||
|
||
res.writeHead(200, { | ||
"Content-Type": "text/plain", | ||
"Content-Length": Buffer.byteLength(body) | ||
}); | ||
// HEAD has no body | ||
if (req.method != "HEAD") { | ||
res.write(body); | ||
} | ||
res.end(); | ||
}).listen(8000); | ||
|
||
// Test standard methods | ||
var methods = ["GET", "POST", "HEAD", "PUT", "DELETE"]; | ||
var curMethod = 0; | ||
|
||
function start(method) { | ||
// Reset each time | ||
xhr = new XMLHttpRequest(); | ||
|
||
xhr.onreadystatechange = function() { | ||
if (this.readyState == 4) { | ||
assert.equal(this.responseText.indexOf("Error: self") > -1, true); | ||
|
||
curMethod++; | ||
|
||
if (curMethod < methods.length) { | ||
console.log("Testing " + methods[curMethod]); | ||
start(methods[curMethod]); | ||
} else { | ||
server.close(); | ||
console.log('done'); | ||
} | ||
} | ||
}; | ||
|
||
var url = "https://localhost:8000/" + method; | ||
xhr.open(method, url); | ||
xhr.send(); | ||
} | ||
|
||
console.log("Testing " + methods[curMethod]); | ||
start(methods[curMethod]); |