// we need to keep track of the order they were sent.
var responses = [];
- var parser = newParser('request');
+ var parser = parsers.alloc();
+ parser.reinitialize('request');
+ parser.socket = socket;
+ if (self.secure) {
+ socket.setSecure(self.credentials);
+ }
+
socket.ondata = function (d, start, end) {
parser.execute(d, start, end - start);
};
}
var url = require("url").parse(url);
-
+
var hasHost = false;
- for (var i in headers) {
- if (i.toLowerCase() === "host") {
- hasHost = true;
- break;
+ if (headers instanceof Array) {
+ for (var i = 0, l = headers.length; i < l; i++) {
+ if (headers[i][0].toLowerCase() === 'host') {
+ hasHost = true;
+ break;
+ }
+ }
+ } else if (typeof headers === "Object") {
+ var keys = Object.keys(headers);
+ for (var i = 0, l = keys.length; i < l; i++) {
+ var key = keys[i];
+ if (key.toLowerCase() == 'host') {
+ hasHost = true;
+ break;
+ }
}
}
if (!hasHost) headers["Host"] = url.hostname;
var sys = require("sys");
var fs = require("fs");
var events = require("events");
+var crypto= require("crypto");
+ var dns = require('dns');
var kMinPoolSpace = 128;
var kPoolSize = 40*1024;
var errnoException = binding.errnoException;
var EINPROGRESS = binding.EINPROGRESS;
var ENOENT = binding.ENOENT;
+ var EMFILE = binding.EMFILE;
var END_OF_FILE = 42;
+// Do we have openssl crypto?
+try {
+ var SecureContext = process.binding('crypto').SecureContext;
+ var SecureStream = process.binding('crypto').SecureStream;
+ var have_crypto = true;
+} catch (e) {
+ var have_crypto = false;
+}
// IDLE TIMEOUTS
//
pool,
pool.used,
pool.length - pool.used);
+ }
} catch (e) {
+ if (this.forceClose) this.forceClose(e);
+ self.destroy(e);
return;
}
// 3. Slice out remaining
// 4. Unshift remaining onto _writeQueue. Return false.
Stream.prototype._writeOut = function (data, encoding) {
- if (!this.writable) throw new Error('Stream is not writable');
-
+ if (!this.writable) {
+ if (this.secure) return false;
+ else throw new Error('Stream is not writable');
+ }
+ if (data.length == 0) return true;
var buffer, off, len;
var bytesWritten, charsWritten;
}
if (encoding == 'utf8' || encoding == 'utf-8') {
- bytesWritten = pool.utf8Write(data, pool.used);
+ // default to utf8
+ bytesWritten = pool.write(data, 'utf8', pool.used);
// XXX Hacky way to find out the number of characters written.
// Waiting for a more optimal way: http://codereview.chromium.org/1539013
- var _s = pool.utf8Slice(pool.used, pool.used + bytesWritten);
+ var _s = pool.toString('utf8', pool.used, pool.used + bytesWritten);
charsWritten = _s.length;
- } else if (encoding == 'ascii') {
- bytesWritten = pool.asciiWrite(data, pool.used);
- charsWritten = bytesWritten;
- assert(charsWritten <= data.length);
} else {
- bytesWritten = pool.binaryWrite(data, pool.used);
+ bytesWritten = pool.write(data, encoding, pool.used);
charsWritten = bytesWritten;
- assert(charsWritten <= data.length);
}
- assert(bytesWritten > 0);
+ if (encoding) assert(bytesWritten > 0);
buffer = pool;
len = bytesWritten;
}
}
-
- // Send the buffer.
-
try {
- bytesWritten = write(this.fd, buffer, off, len);
+ if (this.secure) {
+ if (!buffer) return false;
+ bytesWritten = this.secureStream.writeInject(buffer, off, len);
+ if (!securePool) allocNewSecurePool();
+ var secureLen = this.secureStream.writeExtract(securePool, 0, securePool.length);
+ if (secureLen==-1) {
+ // Check our read again for secure handshake
+ this._readWatcher.callback();
+ secureBytesWritten = 0;
+ } else {
+ var secureBytesWritten = write(this.fd, securePool, 0, secureLen);
+ }
+ if(!this.secureEstablished && this.secureStream.isInitFinished()) {
+ this.secureEstablished = true;
+ if (this._events && this._events['secure']) this.emit('secure');
+ }
+ } else {
+ bytesWritten = write(this.fd, buffer, off, len);
+ }
} catch (e) {
- this.forceClose(e);
+ this.destroy(e);
return false;
}
timeout.unenroll(this);
+ if (this.secure) {
+ this.secureStream.close();
+ }
+
// FIXME Bug when this.fd == 0
if (typeof this.fd == 'number') {
- close(this.fd);
+ closeFD(this.fd);
this.fd = null;
process.nextTick(function () {
if (exception) self.emit('error', exception);
exports->Set(String::New("fs"), String::New(native_fs));
exports->Set(String::New("http"), String::New(native_http));
exports->Set(String::New("http_old"), String::New(native_http_old));
+ exports->Set(String::New("crypto"), String::New(native_crypto));
exports->Set(String::New("ini"), String::New(native_ini));
exports->Set(String::New("mjsunit"), String::New(native_mjsunit));
- exports->Set(String::New("multipart"), String::New(native_multipart));
exports->Set(String::New("net"), String::New(native_net));
exports->Set(String::New("posix"), String::New(native_posix));
exports->Set(String::New("querystring"), String::New(native_querystring));
deps/http_parser
deps/coupling
"""
- node.add_objects = 'ev eio evcom http_parser coupling'
+
+ node.includes += ' deps/c-ares/' + bld.env['DEST_OS'] + '-' + bld.env['DEST_CPU']
+
+
+ node.add_objects = 'cares ev eio evcom http_parser coupling'
node.uselib_local = ''
- node.uselib = 'OPENSSL GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL'
- node.uselib = 'RT GNUTLS GPGERROR CARES V8 EXECINFO DL KVM SOCKET NSL'
++ node.uselib = 'RT OPENSSL GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL'
else:
node.includes = """
src/
"""
node.add_objects = 'eio evcom http_parser coupling'
node.uselib_local = 'eio'
- node.uselib = 'EV OPENSSL GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL'
- node.uselib = 'RT EV GNUTLS GPGERROR CARES V8 EXECINFO DL KVM SOCKET NSL'
++ node.uselib = 'RT EV OPENSSL GNUTLS GPGERROR UDNS V8 EXECINFO DL KVM SOCKET NSL'
node.install_path = '${PREFIX}/lib'
node.install_path = '${PREFIX}/bin'