mirror of https://github.com/lukechilds/node.git
Browse Source
test/simple/test-url.js:31:(0110) Line too long (82 characters). test/simple/test-url.js:39:(0110) Line too long (85 characters). test/simple/test-url.js:40:(0110) Line too long (92 characters).v0.7.4-release
Oleg Efimov
14 years ago
committed by
Ryan Dahl
72 changed files with 1530 additions and 1427 deletions
@ -1,15 +1,15 @@ |
|||||
var common = require('../common'); |
var common = require('../common'); |
||||
var assert = require('assert');; |
var assert = require('assert'); |
||||
|
|
||||
var complete = false; |
var complete = false; |
||||
var idle = new process.IdleWatcher(); |
var idle = new process.IdleWatcher(); |
||||
idle.callback = function () { |
idle.callback = function() { |
||||
complete = true; |
complete = true; |
||||
idle.stop(); |
idle.stop(); |
||||
}; |
}; |
||||
idle.setPriority(process.EVMAXPRI); |
idle.setPriority(process.EVMAXPRI); |
||||
idle.start(); |
idle.start(); |
||||
|
|
||||
process.addListener('exit', function () { |
process.addListener('exit', function() { |
||||
assert.ok(complete); |
assert.ok(complete); |
||||
}); |
}); |
||||
|
@ -1,29 +1,31 @@ |
|||||
// Example of new TLS API. Test with:
|
// Example of new TLS API. Test with:
|
||||
//
|
//
|
||||
// openssl s_client -connect localhost:12346 -key test/fixtures/agent.key -cert test/fixtures/agent.crt
|
// $> openssl s_client -connect localhost:12346 \
|
||||
// openssl s_client -connect localhost:12346
|
// -key test/fixtures/agent.key -cert test/fixtures/agent.crt
|
||||
|
//
|
||||
|
// $> openssl s_client -connect localhost:12346
|
||||
//
|
//
|
||||
var common = require('../common'); |
var common = require('../common'); |
||||
var tls = require('tls'); |
var tls = require('tls'); |
||||
var fs = require('fs'); |
var fs = require('fs'); |
||||
var join = require('path').join; |
var join = require('path').join; |
||||
|
|
||||
var key = fs.readFileSync(join(common.fixturesDir, "agent.key")).toString(); |
var key = fs.readFileSync(join(common.fixturesDir, 'agent.key')).toString(); |
||||
var cert = fs.readFileSync(join(common.fixturesDir, "agent.crt")).toString(); |
var cert = fs.readFileSync(join(common.fixturesDir, 'agent.crt')).toString(); |
||||
|
|
||||
s = tls.Server({ key: key, cert: cert, unauthorizedPeers: false }); |
s = tls.Server({key: key, cert: cert, unauthorizedPeers: false}); |
||||
|
|
||||
s.listen(common.PORT, function () { |
s.listen(common.PORT, function() { |
||||
console.log("TLS server on 127.0.0.1:%d", common.PORT); |
console.log('TLS server on 127.0.0.1:%d', common.PORT); |
||||
}); |
}); |
||||
|
|
||||
|
|
||||
s.on('authorized', function (c) { |
s.on('authorized', function(c) { |
||||
console.log("authed connection"); |
console.log('authed connection'); |
||||
c.end("bye authorized friend.\n"); |
c.end('bye authorized friend.\n'); |
||||
}); |
}); |
||||
|
|
||||
s.on('unauthorized', function (c, e) { |
s.on('unauthorized', function(c, e) { |
||||
console.log("unauthed connection: %s", e); |
console.log('unauthed connection: %s', e); |
||||
c.end("bye unauthorized person.\n"); |
c.end('bye unauthorized person.\n'); |
||||
}); |
}); |
||||
|
@ -1,42 +1,43 @@ |
|||||
var common = require('../common'); |
var common = require('../common'); |
||||
var assert = require('assert');; |
var assert = require('assert'); |
||||
var util=require('util'); |
|
||||
var net=require('net'); |
|
||||
var fs=require('fs'); |
|
||||
var crypto=require('crypto'); |
|
||||
|
|
||||
//var client = net.createConnection(4443, "localhost");
|
var util = require('util'); |
||||
var client = net.createConnection(443, "www.microsoft.com"); |
var net = require('net'); |
||||
//var client = net.createConnection(443, "www.google.com");
|
var fs = require('fs'); |
||||
|
var crypto = require('crypto'); |
||||
|
|
||||
var caPem = fs.readFileSync(common.fixturesDir+"/msca.pem"); |
//var client = net.createConnection(4443, 'localhost');
|
||||
//var caPem = fs.readFileSync("ca.pem");
|
var client = net.createConnection(443, 'www.microsoft.com'); |
||||
|
//var client = net.createConnection(443, 'www.google.com');
|
||||
|
|
||||
try{ |
var caPem = fs.readFileSync(common.fixturesDir + '/msca.pem'); |
||||
var credentials = crypto.createCredentials({ca:caPem}); |
//var caPem = fs.readFileSync('ca.pem');
|
||||
|
|
||||
|
try { |
||||
|
var credentials = crypto.createCredentials({ca: caPem}); |
||||
} catch (e) { |
} catch (e) { |
||||
console.log("Not compiled with OPENSSL support."); |
console.log('Not compiled with OPENSSL support.'); |
||||
process.exit(); |
process.exit(); |
||||
} |
} |
||||
|
|
||||
client.setEncoding("UTF8"); |
client.setEncoding('UTF8'); |
||||
client.addListener("connect", function () { |
client.addListener('connect', function() { |
||||
console.log("client connected."); |
console.log('client connected.'); |
||||
client.setSecure(credentials); |
client.setSecure(credentials); |
||||
}); |
}); |
||||
|
|
||||
client.addListener("secure", function () { |
client.addListener('secure', function() { |
||||
console.log("client secure : "+JSON.stringify(client.getCipher())); |
console.log('client secure : ' + JSON.stringify(client.getCipher())); |
||||
console.log(JSON.stringify(client.getPeerCertificate())); |
console.log(JSON.stringify(client.getPeerCertificate())); |
||||
console.log("verifyPeer : "+client.verifyPeer()); |
console.log('verifyPeer : ' + client.verifyPeer()); |
||||
client.write("GET / HTTP/1.0\r\n\r\n"); |
client.write('GET / HTTP/1.0\r\n\r\n'); |
||||
}); |
}); |
||||
|
|
||||
client.addListener("data", function (chunk) { |
client.addListener('data', function(chunk) { |
||||
common.error(chunk); |
common.error(chunk); |
||||
}); |
}); |
||||
|
|
||||
client.addListener("end", function () { |
client.addListener('end', function() { |
||||
console.log("client disconnected."); |
console.log('client disconnected.'); |
||||
}); |
}); |
||||
|
|
||||
|
@ -1,44 +1,44 @@ |
|||||
var common = require('../common'); |
var common = require('../common'); |
||||
var assert = require('assert'); |
var assert = require('assert'); |
||||
var net = require("net"); |
var net = require('net'); |
||||
var http = require("http"); |
var http = require('http'); |
||||
|
|
||||
var body = "hello world\n"; |
var body = 'hello world\n'; |
||||
var server_response = ""; |
var server_response = ''; |
||||
var client_got_eof = false; |
var client_got_eof = false; |
||||
|
|
||||
var server = http.createServer(function (req, res) { |
var server = http.createServer(function(req, res) { |
||||
assert.equal('1.0', req.httpVersion); |
assert.equal('1.0', req.httpVersion); |
||||
assert.equal(1, req.httpVersionMajor); |
assert.equal(1, req.httpVersionMajor); |
||||
assert.equal(0, req.httpVersionMinor); |
assert.equal(0, req.httpVersionMinor); |
||||
res.writeHead(200, {"Content-Type": "text/plain"}); |
res.writeHead(200, {'Content-Type': 'text/plain'}); |
||||
res.end(body); |
res.end(body); |
||||
}) |
}); |
||||
server.listen(common.PORT); |
server.listen(common.PORT); |
||||
|
|
||||
server.addListener("listening", function() { |
server.addListener('listening', function() { |
||||
var c = net.createConnection(common.PORT); |
var c = net.createConnection(common.PORT); |
||||
|
|
||||
c.setEncoding("utf8"); |
c.setEncoding('utf8'); |
||||
|
|
||||
c.addListener("connect", function () { |
c.addListener('connect', function() { |
||||
c.write( "GET / HTTP/1.0\r\n\r\n" ); |
c.write('GET / HTTP/1.0\r\n\r\n'); |
||||
}); |
}); |
||||
|
|
||||
c.addListener("data", function (chunk) { |
c.addListener('data', function(chunk) { |
||||
console.log(chunk); |
console.log(chunk); |
||||
server_response += chunk; |
server_response += chunk; |
||||
}); |
}); |
||||
|
|
||||
c.addListener("end", function () { |
c.addListener('end', function() { |
||||
client_got_eof = true; |
client_got_eof = true; |
||||
c.end(); |
c.end(); |
||||
server.close(); |
server.close(); |
||||
}); |
}); |
||||
}); |
}); |
||||
|
|
||||
process.addListener("exit", function () { |
process.addListener('exit', function() { |
||||
var m = server_response.split("\r\n\r\n"); |
var m = server_response.split('\r\n\r\n'); |
||||
assert.equal(m[1], body); |
assert.equal(m[1], body); |
||||
assert.equal(true, client_got_eof); |
assert.equal(true, client_got_eof); |
||||
}); |
}); |
||||
|
@ -1,48 +1,47 @@ |
|||||
var common = require('../common'); |
var common = require('../common'); |
||||
var assert = require('assert'); |
var assert = require('assert'); |
||||
var http = require('http'); |
var http = require('http'); |
||||
var url = require("url"); |
var url = require('url'); |
||||
|
|
||||
var body1_s = "1111111111111111"; |
var body1_s = '1111111111111111'; |
||||
var body2_s = "22222"; |
var body2_s = '22222'; |
||||
|
|
||||
var server = http.createServer(function (req, res) { |
var server = http.createServer(function(req, res) { |
||||
var body = url.parse(req.url).pathname === "/1" ? body1_s : body2_s; |
var body = url.parse(req.url).pathname === '/1' ? body1_s : body2_s; |
||||
res.writeHead(200, { "Content-Type": "text/plain" |
res.writeHead(200, |
||||
, "Content-Length": body.length |
{'Content-Type': 'text/plain', 'Content-Length': body.length}); |
||||
}); |
|
||||
res.end(body); |
res.end(body); |
||||
}); |
}); |
||||
server.listen(common.PORT); |
server.listen(common.PORT); |
||||
|
|
||||
var body1 = ""; |
var body1 = ''; |
||||
var body2 = ""; |
var body2 = ''; |
||||
|
|
||||
server.addListener("listening", function() { |
server.addListener('listening', function() { |
||||
var client = http.createClient(common.PORT); |
var client = http.createClient(common.PORT); |
||||
|
|
||||
var req1 = client.request("/1") |
var req1 = client.request('/1'); |
||||
req1.end(); |
req1.end(); |
||||
req1.addListener('response', function (res1) { |
req1.addListener('response', function(res1) { |
||||
res1.setEncoding("utf8"); |
res1.setEncoding('utf8'); |
||||
|
|
||||
res1.addListener('data', function (chunk) { |
res1.addListener('data', function(chunk) { |
||||
body1 += chunk; |
body1 += chunk; |
||||
}); |
}); |
||||
|
|
||||
res1.addListener('end', function () { |
res1.addListener('end', function() { |
||||
var req2 = client.request("/2"); |
var req2 = client.request('/2'); |
||||
req2.end(); |
req2.end(); |
||||
req2.addListener('response', function (res2) { |
req2.addListener('response', function(res2) { |
||||
res2.setEncoding("utf8"); |
res2.setEncoding('utf8'); |
||||
res2.addListener('data', function (chunk) { body2 += chunk; }); |
res2.addListener('data', function(chunk) { body2 += chunk; }); |
||||
res2.addListener('end', function () { server.close(); }); |
res2.addListener('end', function() { server.close(); }); |
||||
}); |
}); |
||||
}); |
}); |
||||
}); |
}); |
||||
}); |
}); |
||||
|
|
||||
process.addListener("exit", function () { |
process.addListener('exit', function() { |
||||
assert.equal(body1_s, body1); |
assert.equal(body1_s, body1); |
||||
assert.equal(body2_s, body2); |
assert.equal(body2_s, body2); |
||||
}); |
}); |
||||
|
@ -1,80 +1,80 @@ |
|||||
var common = require('../common'); |
var common = require('../common'); |
||||
var assert = require('assert'); |
var assert = require('assert'); |
||||
var http = require('http'); |
var http = require('http'); |
||||
var url = require("url"); |
var url = require('url'); |
||||
|
|
||||
function p (x) { |
function p(x) { |
||||
common.error(common.inspect(x)); |
common.error(common.inspect(x)); |
||||
} |
} |
||||
|
|
||||
var responses_sent = 0; |
var responses_sent = 0; |
||||
var responses_recvd = 0; |
var responses_recvd = 0; |
||||
var body0 = ""; |
var body0 = ''; |
||||
var body1 = ""; |
var body1 = ''; |
||||
|
|
||||
var server = http.Server(function (req, res) { |
var server = http.Server(function(req, res) { |
||||
if (responses_sent == 0) { |
if (responses_sent == 0) { |
||||
assert.equal("GET", req.method); |
assert.equal('GET', req.method); |
||||
assert.equal("/hello", url.parse(req.url).pathname); |
assert.equal('/hello', url.parse(req.url).pathname); |
||||
|
|
||||
console.dir(req.headers); |
console.dir(req.headers); |
||||
assert.equal(true, "accept" in req.headers); |
assert.equal(true, 'accept' in req.headers); |
||||
assert.equal("*/*", req.headers["accept"]); |
assert.equal('*/*', req.headers['accept']); |
||||
|
|
||||
assert.equal(true, "foo" in req.headers); |
assert.equal(true, 'foo' in req.headers); |
||||
assert.equal("bar", req.headers["foo"]); |
assert.equal('bar', req.headers['foo']); |
||||
} |
} |
||||
|
|
||||
if (responses_sent == 1) { |
if (responses_sent == 1) { |
||||
assert.equal("POST", req.method); |
assert.equal('POST', req.method); |
||||
assert.equal("/world", url.parse(req.url).pathname); |
assert.equal('/world', url.parse(req.url).pathname); |
||||
this.close(); |
this.close(); |
||||
} |
} |
||||
|
|
||||
req.addListener('end', function () { |
req.addListener('end', function() { |
||||
res.writeHead(200, {"Content-Type": "text/plain"}); |
res.writeHead(200, {'Content-Type': 'text/plain'}); |
||||
res.write("The path was " + url.parse(req.url).pathname); |
res.write('The path was ' + url.parse(req.url).pathname); |
||||
res.end(); |
res.end(); |
||||
responses_sent += 1; |
responses_sent += 1; |
||||
}); |
}); |
||||
|
|
||||
//assert.equal("127.0.0.1", res.connection.remoteAddress);
|
//assert.equal('127.0.0.1', res.connection.remoteAddress);
|
||||
}); |
}); |
||||
server.listen(common.PORT); |
server.listen(common.PORT); |
||||
|
|
||||
server.addListener("listening", function() { |
server.addListener('listening', function() { |
||||
var client = http.createClient(common.PORT); |
var client = http.createClient(common.PORT); |
||||
var req = client.request("/hello", {"Accept": "*/*", "Foo": "bar"}); |
var req = client.request('/hello', {'Accept': '*/*', 'Foo': 'bar'}); |
||||
req.end(); |
req.end(); |
||||
req.addListener('response', function (res) { |
req.addListener('response', function(res) { |
||||
assert.equal(200, res.statusCode); |
assert.equal(200, res.statusCode); |
||||
responses_recvd += 1; |
responses_recvd += 1; |
||||
res.setEncoding("utf8"); |
res.setEncoding('utf8'); |
||||
res.addListener('data', function (chunk) { body0 += chunk; }); |
res.addListener('data', function(chunk) { body0 += chunk; }); |
||||
common.debug("Got /hello response"); |
common.debug('Got /hello response'); |
||||
}); |
}); |
||||
|
|
||||
setTimeout(function () { |
setTimeout(function() { |
||||
req = client.request("POST", "/world"); |
req = client.request('POST', '/world'); |
||||
req.end(); |
req.end(); |
||||
req.addListener('response',function (res) { |
req.addListener('response', function(res) { |
||||
assert.equal(200, res.statusCode); |
assert.equal(200, res.statusCode); |
||||
responses_recvd += 1; |
responses_recvd += 1; |
||||
res.setEncoding("utf8"); |
res.setEncoding('utf8'); |
||||
res.addListener('data', function (chunk) { body1 += chunk; }); |
res.addListener('data', function(chunk) { body1 += chunk; }); |
||||
common.debug("Got /world response"); |
common.debug('Got /world response'); |
||||
}); |
}); |
||||
}, 1); |
}, 1); |
||||
}); |
}); |
||||
|
|
||||
process.addListener("exit", function () { |
process.addListener('exit', function() { |
||||
common.debug("responses_recvd: " + responses_recvd); |
common.debug('responses_recvd: ' + responses_recvd); |
||||
assert.equal(2, responses_recvd); |
assert.equal(2, responses_recvd); |
||||
|
|
||||
common.debug("responses_sent: " + responses_sent); |
common.debug('responses_sent: ' + responses_sent); |
||||
assert.equal(2, responses_sent); |
assert.equal(2, responses_sent); |
||||
|
|
||||
assert.equal("The path was /hello", body0); |
assert.equal('The path was /hello', body0); |
||||
assert.equal("The path was /world", body1); |
assert.equal('The path was /world', body1); |
||||
}); |
}); |
||||
|
|
||||
|
Loading…
Reference in new issue