Browse Source

http: remove legacy http library

v0.7.4-release
Ben Noordhuis 14 years ago
parent
commit
bc7cfd7cd7
  1. 1102
      lib/http.js
  2. 1500
      lib/http2.js
  3. 48
      lib/https.js
  4. 84
      lib/https2.js
  5. 8
      src/node.cc
  6. 10
      src/node.js

1102
lib/http.js

File diff suppressed because it is too large

1500
lib/http2.js

File diff suppressed because it is too large

48
lib/https.js

@ -50,56 +50,32 @@ exports.createServer = function(opts, requestListener) {
// HTTPS agents. // HTTPS agents.
var agents = {};
function createConnection(port, host, options) {
return tls.connect(port, host, options);
};
function Agent(options) { function Agent(options) {
http.Agent.call(this, options); http.Agent.call(this, options);
} this.createConnection = createConnection;
};
inherits(Agent, http.Agent); inherits(Agent, http.Agent);
Agent.prototype.defaultPort = 443; Agent.prototype.defaultPort = 443;
var globalAgent = new Agent();
Agent.prototype._getConnection = function(options, cb) { exports.globalAgent = globalAgent;
if (process.features.tls_npn && !this.options.NPNProtocols) {
this.options.NPNProtocols = ['http/1.1', 'http/1.0'];
}
var s = tls.connect(options.port, options.host, this.options, function() {
// do other checks here?
if (cb) cb();
});
return s;
};
function getAgent(options) {
if (!options.port) options.port = 443;
var id = options.host + ':' + options.port;
var agent = agents[id];
if (!agent) {
agent = agents[id] = new Agent(options);
}
return agent;
}
exports.getAgent = getAgent;
exports.Agent = Agent; exports.Agent = Agent;
exports.request = function(options, cb) { exports.request = function(options, cb) {
if (options.agent === undefined) { if (options.agent === undefined) {
options.agent = getAgent(options); options.agent = globalAgent;
} else if (options.agent === false) {
options.agent = new Agent(options);
} }
return http._requestFromAgent(options, cb); options.createConnection = createConnection;
options.defaultPort = options.defaultPort || 443;
return http.request(options, cb);
}; };
exports.get = function(options, cb) { exports.get = function(options, cb) {
options.method = 'GET'; options.method = 'GET';
var req = exports.request(options, cb); var req = exports.request(options, cb);

84
lib/https2.js

@ -1,84 +0,0 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var tls = require('tls');
var http = require('http');
var inherits = require('util').inherits;
function Server(opts, requestListener) {
if (!(this instanceof Server)) return new Server(opts, requestListener);
if (process.features.tls_npn && !opts.NPNProtocols) {
opts.NPNProtocols = ['http/1.1', 'http/1.0'];
}
tls.Server.call(this, opts, http._connectionListener);
this.httpAllowHalfOpen = false;
if (requestListener) {
this.addListener('request', requestListener);
}
}
inherits(Server, tls.Server);
exports.Server = Server;
exports.createServer = function(opts, requestListener) {
return new Server(opts, requestListener);
};
// HTTPS agents.
function createConnection(port, host, options) {
return tls.connect(port, host, options);
};
function Agent(options) {
http.Agent.call(this, options);
this.createConnection = createConnection;
};
inherits(Agent, http.Agent);
Agent.prototype.defaultPort = 443;
var globalAgent = new Agent();
exports.globalAgent = globalAgent;
exports.Agent = Agent;
exports.request = function(options, cb) {
if (options.agent === undefined) {
options.agent = globalAgent;
}
options.createConnection = createConnection;
options.defaultPort = options.defaultPort || 443;
return http.request(options, cb);
};
exports.get = function(options, cb) {
options.method = 'GET';
var req = exports.request(options, cb);
req.end();
return req;
};

8
src/node.cc

@ -144,9 +144,6 @@ static Persistent<String> tick_callback_sym;
static bool use_uv = true; static bool use_uv = true;
// disabled by default for now
static bool use_http1 = false;
#ifdef OPENSSL_NPN_NEGOTIATED #ifdef OPENSSL_NPN_NEGOTIATED
static bool use_npn = true; static bool use_npn = true;
#else #else
@ -2025,7 +2022,6 @@ static Handle<Object> GetFeatures() {
); );
obj->Set(String::NewSymbol("uv"), Boolean::New(use_uv)); obj->Set(String::NewSymbol("uv"), Boolean::New(use_uv));
obj->Set(String::NewSymbol("http1"), Boolean::New(use_http1));
obj->Set(String::NewSymbol("ipv6"), True()); // TODO ping libuv obj->Set(String::NewSymbol("ipv6"), True()); // TODO ping libuv
obj->Set(String::NewSymbol("tls_npn"), Boolean::New(use_npn)); obj->Set(String::NewSymbol("tls_npn"), Boolean::New(use_npn));
obj->Set(String::NewSymbol("tls_sni"), Boolean::New(use_sni)); obj->Set(String::NewSymbol("tls_sni"), Boolean::New(use_sni));
@ -2274,7 +2270,6 @@ static void PrintHelp() {
" --vars print various compiled-in variables\n" " --vars print various compiled-in variables\n"
" --max-stack-size=val set max v8 stack size (bytes)\n" " --max-stack-size=val set max v8 stack size (bytes)\n"
" --use-legacy use the legacy backend (default: libuv)\n" " --use-legacy use the legacy backend (default: libuv)\n"
" --use-http1 use the legacy http library\n"
"\n" "\n"
"Enviromental variables:\n" "Enviromental variables:\n"
"NODE_PATH ':'-separated list of directories\n" "NODE_PATH ':'-separated list of directories\n"
@ -2299,9 +2294,6 @@ static void ParseArgs(int argc, char **argv) {
} else if (!strcmp(arg, "--use-legacy")) { } else if (!strcmp(arg, "--use-legacy")) {
use_uv = false; use_uv = false;
argv[i] = const_cast<char*>(""); argv[i] = const_cast<char*>("");
} else if (!strcmp(arg, "--use-http1")) {
use_http1 = true;
argv[i] = const_cast<char*>("");
} else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) { } else if (strcmp(arg, "--version") == 0 || strcmp(arg, "-v") == 0) {
printf("%s\n", NODE_VERSION); printf("%s\n", NODE_VERSION);
exit(0); exit(0);

10
src/node.js

@ -35,10 +35,6 @@
process.features.uv = process.env.NODE_USE_UV != '0'; process.features.uv = process.env.NODE_USE_UV != '0';
} }
if ('NODE_USE_HTTP1' in process.env) {
process.features.http1 = process.env.NODE_USE_HTTP1 != '0';
}
// make sure --use-uv is propagated to child processes // make sure --use-uv is propagated to child processes
if (process.features.uv) { if (process.features.uv) {
process.env.NODE_USE_UV = '1'; process.env.NODE_USE_UV = '1';
@ -451,12 +447,6 @@
// backend. // backend.
function translateId(id) { function translateId(id) {
switch (id) { switch (id) {
case 'http':
return process.features.http1 ? 'http' : 'http2';
case 'https':
return process.features.http1 ? 'https' : 'https2';
case 'net': case 'net':
return process.features.uv ? 'net_uv' : 'net_legacy'; return process.features.uv ? 'net_uv' : 'net_legacy';

Loading…
Cancel
Save