Skip to content

Instantly share code, notes, and snippets.

@webholics
Created April 12, 2011 14:35
Show Gist options
  • Save webholics/915603 to your computer and use it in GitHub Desktop.
Save webholics/915603 to your computer and use it in GitHub Desktop.
test for node.js issue 670 https://github.com/joyent/node/issues/670
var urlToResolve = 'https://localhost/';
var https = require('https'),
url = require('url');
var parsedUrl = url.parse(urlToResolve);
var path = parsedUrl.pathname;
var options = {
host: parsedUrl.hostname,
path: path,
port: 8443
};
var request = https.get(options, function(response) {
response.socket.on('error', function(e) {
console.log('Error on response socket.');
});
var body = '';
response.on('data', function(chunk) {
body += chunk;
console.log('Response data.');
});
response.on('end', function() {
console.log('Response end.');
console.log(body);
});
}).on('error', function(e) {
console.log('Error on get.');
});
-----BEGIN CERTIFICATE-----
MIICYzCCAcwCCQD5jx1Aa0dytjANBgkqhkiG9w0BAQQFADB2MQswCQYDVQQGEwJU
UzENMAsGA1UECBMEVGVzdDENMAsGA1UEBxMEVGVzdDEWMBQGA1UEChMNVGVzdCBF
dmVudGxldDENMAsGA1UECxMEVGVzdDENMAsGA1UEAxMEVGVzdDETMBEGCSqGSIb3
DQEJARYEVGVzdDAeFw0wODA3MDgyMTExNDJaFw0xMDAyMDgwODE1MTBaMHYxCzAJ
BgNVBAYTAlRTMQ0wCwYDVQQIEwRUZXN0MQ0wCwYDVQQHEwRUZXN0MRYwFAYDVQQK
Ew1UZXN0IEV2ZW50bGV0MQ0wCwYDVQQLEwRUZXN0MQ0wCwYDVQQDEwRUZXN0MRMw
EQYJKoZIhvcNAQkBFgRUZXN0MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDM
WcyeIiHQuEGQxgTIvu0aOW4iRFAyUEi8pLWNCxMEHglF8k6OxFVq7XWZMDnDFVnb
ZjmQh5Tc21Ae6cXzxXln578fROXHEzXo3Is8HUlq3ug1yYOGHjxw++Opjf1uoHwP
EBUKsz/flS7knuscgFM9FO05KSPn2wHnZeIDta4yTwIDAQABMA0GCSqGSIb3DQEB
BAUAA4GB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I server example based on gevent.pywsgi"""
from gevent import pywsgi
def hello_world(env, start_response):
if env['PATH_INFO'] == '/':
start_response('200 OK', [('Content-Type', 'text/html')])
return ["<b>hello world</b>"]
else:
start_response('404 Not Found', [('Content-Type', 'text/html')])
return ['<h1>Not Found</h1>']
print 'Serving on https://127.0.0.1:8443'
server = pywsgi.WSGIServer(('0.0.0.0', 8443), hello_world, keyfile='server.key', certfile='server.crt')
# to start the server asynchronously, call server.start()
# we use blocking serve_forever() here because we have no other jobs
server.serve_forever()
@webholics
Copy link
Author

Requires Python Gevent:

aptitude install python-setuptools python-dev libevent-dev
easy_install gevent

Start server:

python server.py

Run client:

node client.js

Throws error (in 1 out of 10 cases):

TypeError: Cannot call method 'emit' of undefined
    at CleartextStream. (http.js:1201:9)
    at CleartextStream.emit (events.js:81:20)
    at Socket.onerror (tls.js:874:17)
    at Socket.emit (events.js:64:17)
    at Array. (net.js:824:27)
    at EventEmitter._tickCallback (node.js:126:26)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment