passenger 5.0.21 → 5.0.22
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of passenger might be problematic. Click here for more details.
- checksums.yaml +8 -8
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/CHANGELOG +38 -2
- data/CONTRIBUTORS +3 -0
- data/README.md +5 -1
- data/bin/passenger-status +2 -7
- data/build/agent.rb +2 -0
- data/build/cxx_dependency_map.rb +1464 -162
- data/build/node_tests.rb +1 -1
- data/build/packaging.rb +1 -1
- data/dev/ci/run_travis.sh +1 -1
- data/dev/vagrant/provision.sh +1 -1
- data/npm-shrinkwrap.json +635 -125
- data/package.json +1 -1
- data/resources/templates/standalone/config.erb +33 -161
- data/resources/templates/standalone/global.erb +15 -0
- data/resources/templates/standalone/http.erb +40 -0
- data/resources/templates/standalone/mass_deployment_default_server.erb +11 -0
- data/resources/templates/standalone/rails_asset_pipeline.erb +22 -0
- data/resources/templates/standalone/server.erb +58 -0
- data/src/agent/Core/ApiServer.h +37 -32
- data/src/agent/Core/ApplicationPool/BasicGroupInfo.h +1 -1
- data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +6 -0
- data/src/agent/Core/ApplicationPool/Common.h +1 -1
- data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +4 -0
- data/src/agent/Core/ApplicationPool/Implementation.cpp +2 -2
- data/src/agent/Core/ApplicationPool/Options.h +18 -1
- data/src/agent/Core/ApplicationPool/Pool.h +1 -1
- data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +6 -6
- data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +3 -3
- data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +6 -0
- data/src/agent/Core/ApplicationPool/Process.h +6 -1
- data/src/agent/Core/ApplicationPool/Socket.h +9 -12
- data/src/agent/Core/Controller.h +422 -0
- data/src/agent/Core/{RequestHandler → Controller}/AppResponse.h +2 -0
- data/src/agent/Core/{RequestHandler → Controller}/BufferBody.cpp +27 -5
- data/src/agent/Core/{RequestHandler → Controller}/CheckoutSession.cpp +61 -31
- data/src/agent/Core/{RequestHandler → Controller}/Client.h +5 -2
- data/src/agent/Core/{RequestHandler → Controller}/ForwardResponse.cpp +93 -42
- data/src/agent/Core/{RequestHandler → Controller}/Hooks.cpp +107 -60
- data/src/agent/Core/Controller/Implementation.cpp +38 -0
- data/src/agent/Core/{RequestHandler → Controller}/InitRequest.cpp +134 -80
- data/src/agent/Core/Controller/InitializationAndShutdown.cpp +165 -0
- data/src/agent/Core/{RequestHandler/Utils.cpp → Controller/InternalUtils.cpp} +49 -32
- data/src/agent/Core/Controller/Miscellaneous.cpp +116 -0
- data/src/agent/Core/{RequestHandler → Controller}/Request.h +6 -4
- data/src/agent/Core/{RequestHandler → Controller}/SendRequest.cpp +205 -130
- data/src/agent/Core/Controller/StateInspectionAndConfiguration.cpp +161 -0
- data/src/agent/Core/{RequestHandler → Controller}/TurboCaching.h +3 -0
- data/src/agent/Core/CoreMain.cpp +62 -51
- data/src/agent/Core/OptionParser.h +24 -0
- data/src/agent/Core/ResponseCache.h +5 -5
- data/src/agent/Core/SpawningKit/Config.h +2 -2
- data/src/agent/Core/SpawningKit/SmartSpawner.h +1 -1
- data/src/agent/Core/UnionStation/{Core.h → Context.h} +14 -18
- data/src/agent/Core/UnionStation/StopwatchLog.h +3 -2
- data/src/agent/Core/UnionStation/Transaction.h +7 -7
- data/src/agent/Shared/ApiServerUtils.h +9 -1
- data/src/agent/UstRouter/ApiServer.h +5 -2
- data/src/agent/UstRouter/Controller.h +27 -9
- data/src/agent/UstRouter/UstRouterMain.cpp +1 -0
- data/src/agent/Watchdog/ApiServer.h +5 -2
- data/src/apache2_module/ConfigurationCommands.cpp +7 -0
- data/src/apache2_module/ConfigurationFields.hpp +2 -0
- data/src/apache2_module/ConfigurationSetters.cpp +24 -0
- data/src/apache2_module/CreateDirConfig.cpp +1 -0
- data/src/apache2_module/Hooks.cpp +6 -5
- data/src/apache2_module/MergeDirConfig.cpp +7 -0
- data/src/apache2_module/SetHeaders.cpp +5 -0
- data/src/cxx_supportlib/Constants.h +5 -3
- data/src/cxx_supportlib/SafeLibev.h +2 -1
- data/src/cxx_supportlib/UnionStationFilterSupport.h +2 -1
- data/src/cxx_supportlib/Utils/ReleaseableScopedPointer.h +70 -0
- data/src/cxx_supportlib/vendor-modified/boost/libs/regex/src/regex_raw_buffer.cpp +6 -6
- data/src/helper-scripts/node-loader.js +59 -0
- data/src/nginx_module/CacheLocationConfig.c +48 -0
- data/src/nginx_module/ConfigurationCommands.c +20 -0
- data/src/nginx_module/ConfigurationFields.h +4 -0
- data/src/nginx_module/CreateLocationConfig.c +8 -0
- data/src/nginx_module/MergeLocationConfig.c +12 -0
- data/src/nodejs_supportlib/phusion_passenger/log_express.js +106 -0
- data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +203 -0
- data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +227 -0
- data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +446 -0
- data/src/nodejs_supportlib/vendor-copy/codify/codify.js +44 -0
- data/src/nodejs_supportlib/vendor-copy/codify/package.json +29 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/context.js +200 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/glue.js +488 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/index.js +407 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/index.js +90 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/package.json +40 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/package.json +54 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/listener.js +160 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/index.js +90 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/package.json +40 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/package.json +46 -0
- data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/package.json +56 -0
- data/src/nodejs_supportlib/vendor-copy/network-byte-order/lib/index.js +102 -0
- data/src/nodejs_supportlib/vendor-copy/network-byte-order/package.json +51 -0
- data/src/nodejs_supportlib/vendor-copy/winston/LICENSE +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston.js +165 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/common.js +483 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config.js +62 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/cli-config.js +35 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/npm-config.js +27 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/syslog-config.js +31 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/container.js +127 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/exception.js +56 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/logger.js +701 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports.js +34 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/console.js +128 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/daily-rotate-file.js +601 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/file.js +675 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/http.js +232 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/memory.js +89 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/transport.js +135 -0
- data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/webhook.js +146 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/LICENSE +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/lib/async.js +1283 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/package.json +66 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/support/sync-package-managers.js +53 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/MIT-LICENSE.txt +23 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/colors.js +176 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/trap.js +45 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/zalgo.js +104 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/extendStringPrototype.js +118 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/index.js +12 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/america.js +12 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/rainbow.js +13 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/random.js +8 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/zebra.js +5 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/styles.js +77 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/system/supports-colors.js +61 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/package.json +35 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/safe.js +9 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/themes/generic-logging.js +12 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/cycle.js +170 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/package.json +30 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/LICENSE +20 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/lib/eyes.js +236 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/package.json +42 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/LICENSE.md +11 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/isstream.js +27 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/package.json +42 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/LICENSE +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/lib/pkginfo.js +136 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/package.json +56 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/License +19 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/lib/stack-trace.js +111 -0
- data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/package.json +33 -0
- data/src/nodejs_supportlib/vendor-copy/winston/package.json +87 -0
- data/src/ruby_supportlib/phusion_passenger.rb +3 -4
- data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +19 -2
- data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
- data/src/ruby_supportlib/phusion_passenger/config/list_instances_command.rb +2 -6
- data/src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb +13 -0
- data/src/ruby_supportlib/phusion_passenger/config/restart_app_command.rb +3 -0
- data/src/ruby_supportlib/phusion_passenger/config/utils.rb +9 -7
- data/src/ruby_supportlib/phusion_passenger/config/validate_install_command.rb +8 -1
- data/src/ruby_supportlib/phusion_passenger/constants.rb +3 -1
- data/src/ruby_supportlib/phusion_passenger/native_support.rb +20 -4
- data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +8 -0
- data/src/ruby_supportlib/phusion_passenger/packaging.rb +1 -0
- data/src/ruby_supportlib/phusion_passenger/platform_info/apache_detector.rb +1 -1
- data/src/ruby_supportlib/phusion_passenger/platform_info/operating_system.rb +11 -4
- data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +1 -1
- data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +647 -0
- data/src/ruby_supportlib/phusion_passenger/standalone/config_utils.rb +229 -15
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +35 -323
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +36 -12
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +123 -14
- data/src/ruby_supportlib/phusion_passenger/standalone/status_command.rb +32 -17
- data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +32 -21
- data/src/ruby_supportlib/phusion_passenger/standalone/version_command.rb +5 -5
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +5 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +68 -24
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +9 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +9 -7
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +3 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +8 -5
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +395 -0
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +10 -7
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +14 -0
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml +4 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +16 -0
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +1 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +1 -1
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +44 -17
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +16 -7
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +2 -2
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +1 -1
- metadata +99 -16
- metadata.gz.asc +7 -7
- data/resources/oss-binaries.phusionpassenger.com.crt +0 -248
- data/src/agent/Core/RequestHandler.h +0 -471
@@ -0,0 +1,407 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
if (process.addAsyncListener) throw new Error("Don't require polyfill unless needed");
|
4
|
+
|
5
|
+
var shimmer = require('shimmer')
|
6
|
+
, wrap = shimmer.wrap
|
7
|
+
, massWrap = shimmer.massWrap
|
8
|
+
, wrapCallback = require('./glue.js')
|
9
|
+
, util = require('util')
|
10
|
+
;
|
11
|
+
|
12
|
+
// Shim activator for functions that have callback last
|
13
|
+
function activator(fn) {
|
14
|
+
return function () {
|
15
|
+
var index = arguments.length - 1;
|
16
|
+
if (typeof arguments[index] === "function") {
|
17
|
+
arguments[index] = wrapCallback(arguments[index]);
|
18
|
+
}
|
19
|
+
return fn.apply(this, arguments);
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
// Shim activator for functions that have callback first
|
24
|
+
function activatorFirst(fn) {
|
25
|
+
return function () {
|
26
|
+
if (typeof arguments[0] === "function") {
|
27
|
+
arguments[0] = wrapCallback(arguments[0]);
|
28
|
+
}
|
29
|
+
return fn.apply(this, arguments);
|
30
|
+
};
|
31
|
+
}
|
32
|
+
|
33
|
+
var net = require('net');
|
34
|
+
|
35
|
+
// a polyfill in our polyfill etc so forth -- taken from node master on 2013/10/30
|
36
|
+
if (!net._normalizeConnectArgs) {
|
37
|
+
net._normalizeConnectArgs = function (args) {
|
38
|
+
var options = {};
|
39
|
+
|
40
|
+
function toNumber(x) { return (x = Number(x)) >= 0 ? x : false; }
|
41
|
+
|
42
|
+
if (typeof args[0] === 'object' && args[0] !== null) {
|
43
|
+
// connect(options, [cb])
|
44
|
+
options = args[0];
|
45
|
+
}
|
46
|
+
else if (typeof args[0] === 'string' && toNumber(args[0]) === false) {
|
47
|
+
// connect(path, [cb]);
|
48
|
+
options.path = args[0];
|
49
|
+
}
|
50
|
+
else {
|
51
|
+
// connect(port, [host], [cb])
|
52
|
+
options.port = args[0];
|
53
|
+
if (typeof args[1] === 'string') {
|
54
|
+
options.host = args[1];
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
var cb = args[args.length - 1];
|
59
|
+
return typeof cb === 'function' ? [options, cb] : [options];
|
60
|
+
};
|
61
|
+
}
|
62
|
+
|
63
|
+
wrap(net.Server.prototype, '_listen2', function (original) {
|
64
|
+
return function () {
|
65
|
+
this.on('connection', function (socket) {
|
66
|
+
if (socket._handle) {
|
67
|
+
socket._handle.onread = wrapCallback(socket._handle.onread);
|
68
|
+
}
|
69
|
+
});
|
70
|
+
|
71
|
+
try {
|
72
|
+
return original.apply(this, arguments);
|
73
|
+
}
|
74
|
+
finally {
|
75
|
+
// the handle will only not be set in cases where there has been an error
|
76
|
+
if (this._handle && this._handle.onconnection) {
|
77
|
+
this._handle.onconnection = wrapCallback(this._handle.onconnection);
|
78
|
+
}
|
79
|
+
}
|
80
|
+
};
|
81
|
+
});
|
82
|
+
|
83
|
+
wrap(net.Socket.prototype, 'connect', function (original) {
|
84
|
+
return function () {
|
85
|
+
var args = net._normalizeConnectArgs(arguments);
|
86
|
+
if (args[1]) args[1] = wrapCallback(args[1]);
|
87
|
+
var result = original.apply(this, args);
|
88
|
+
if (this._handle) {
|
89
|
+
this._handle.onread = wrapCallback(this._handle.onread);
|
90
|
+
}
|
91
|
+
return result;
|
92
|
+
};
|
93
|
+
});
|
94
|
+
|
95
|
+
// need unwrapped nextTick for use within < 0.9 async error handling
|
96
|
+
if (!process._fatalException) {
|
97
|
+
process._originalNextTick = process.nextTick;
|
98
|
+
}
|
99
|
+
|
100
|
+
var processors = [];
|
101
|
+
if (process._nextDomainTick) processors.push('_nextDomainTick');
|
102
|
+
if (process._tickDomainCallback) processors.push('_tickDomainCallback');
|
103
|
+
|
104
|
+
massWrap(
|
105
|
+
process,
|
106
|
+
processors,
|
107
|
+
activator
|
108
|
+
);
|
109
|
+
wrap(process, 'nextTick', activatorFirst);
|
110
|
+
|
111
|
+
var asynchronizers = [
|
112
|
+
'setTimeout',
|
113
|
+
'setInterval'
|
114
|
+
];
|
115
|
+
if (global.setImmediate) asynchronizers.push('setImmediate');
|
116
|
+
|
117
|
+
var timers = require('timers');
|
118
|
+
var patchGlobalTimers = global.setTimeout === timers.setTimeout;
|
119
|
+
|
120
|
+
massWrap(
|
121
|
+
timers,
|
122
|
+
asynchronizers,
|
123
|
+
activatorFirst
|
124
|
+
);
|
125
|
+
|
126
|
+
if (patchGlobalTimers) {
|
127
|
+
massWrap(
|
128
|
+
global,
|
129
|
+
asynchronizers,
|
130
|
+
activatorFirst
|
131
|
+
);
|
132
|
+
}
|
133
|
+
|
134
|
+
var dns = require('dns');
|
135
|
+
massWrap(
|
136
|
+
dns,
|
137
|
+
[
|
138
|
+
'lookup',
|
139
|
+
'resolve',
|
140
|
+
'resolve4',
|
141
|
+
'resolve6',
|
142
|
+
'resolveCname',
|
143
|
+
'resolveMx',
|
144
|
+
'resolveNs',
|
145
|
+
'resolveTxt',
|
146
|
+
'resolveSrv',
|
147
|
+
'reverse'
|
148
|
+
],
|
149
|
+
activator
|
150
|
+
);
|
151
|
+
|
152
|
+
if (dns.resolveNaptr) wrap(dns, 'resolveNaptr', activator);
|
153
|
+
|
154
|
+
var fs = require('fs');
|
155
|
+
massWrap(
|
156
|
+
fs,
|
157
|
+
[
|
158
|
+
'watch',
|
159
|
+
'rename',
|
160
|
+
'truncate',
|
161
|
+
'chown',
|
162
|
+
'fchown',
|
163
|
+
'chmod',
|
164
|
+
'fchmod',
|
165
|
+
'stat',
|
166
|
+
'lstat',
|
167
|
+
'fstat',
|
168
|
+
'link',
|
169
|
+
'symlink',
|
170
|
+
'readlink',
|
171
|
+
'realpath',
|
172
|
+
'unlink',
|
173
|
+
'rmdir',
|
174
|
+
'mkdir',
|
175
|
+
'readdir',
|
176
|
+
'close',
|
177
|
+
'open',
|
178
|
+
'utimes',
|
179
|
+
'futimes',
|
180
|
+
'fsync',
|
181
|
+
'write',
|
182
|
+
'read',
|
183
|
+
'readFile',
|
184
|
+
'writeFile',
|
185
|
+
'appendFile',
|
186
|
+
'watchFile',
|
187
|
+
'unwatchFile',
|
188
|
+
"exists",
|
189
|
+
],
|
190
|
+
activator
|
191
|
+
);
|
192
|
+
|
193
|
+
// only wrap lchown and lchmod on systems that have them.
|
194
|
+
if (fs.lchown) wrap(fs, 'lchown', activator);
|
195
|
+
if (fs.lchmod) wrap(fs, 'lchmod', activator);
|
196
|
+
|
197
|
+
// only wrap ftruncate in versions of node that have it
|
198
|
+
if (fs.ftruncate) wrap(fs, 'ftruncate', activator);
|
199
|
+
|
200
|
+
// Wrap zlib streams
|
201
|
+
var zlib;
|
202
|
+
try { zlib = require('zlib'); } catch (err) { }
|
203
|
+
if (zlib && zlib.Deflate && zlib.Deflate.prototype) {
|
204
|
+
var proto = Object.getPrototypeOf(zlib.Deflate.prototype);
|
205
|
+
if (proto._transform) {
|
206
|
+
// streams2
|
207
|
+
wrap(proto, "_transform", activator);
|
208
|
+
}
|
209
|
+
else if (proto.write && proto.flush && proto.end) {
|
210
|
+
// plain ol' streams
|
211
|
+
massWrap(
|
212
|
+
proto,
|
213
|
+
[
|
214
|
+
'write',
|
215
|
+
'flush',
|
216
|
+
'end'
|
217
|
+
],
|
218
|
+
activator
|
219
|
+
);
|
220
|
+
}
|
221
|
+
}
|
222
|
+
|
223
|
+
// Wrap Crypto
|
224
|
+
var crypto;
|
225
|
+
try { crypto = require('crypto'); } catch (err) { }
|
226
|
+
if (crypto) {
|
227
|
+
massWrap(
|
228
|
+
crypto,
|
229
|
+
[
|
230
|
+
'pbkdf2',
|
231
|
+
'randomBytes',
|
232
|
+
'pseudoRandomBytes',
|
233
|
+
],
|
234
|
+
activator
|
235
|
+
);
|
236
|
+
}
|
237
|
+
|
238
|
+
var instrumentPromise = !!global.Promise;
|
239
|
+
|
240
|
+
// Check that global Promise is native
|
241
|
+
if (instrumentPromise) {
|
242
|
+
// shoult not use any methods that have already been wrapped
|
243
|
+
var promiseListener = process.addAsyncListener({
|
244
|
+
create: function create() {
|
245
|
+
instrumentPromise = false;
|
246
|
+
}
|
247
|
+
});
|
248
|
+
|
249
|
+
// should not resolve synchronously
|
250
|
+
global.Promise.resolve(true).then(function notSync() {
|
251
|
+
instrumentPromise = false;
|
252
|
+
});
|
253
|
+
|
254
|
+
process.removeAsyncListener(promiseListener);
|
255
|
+
}
|
256
|
+
|
257
|
+
/*
|
258
|
+
* Native promises use the microtask queue to make all callbacks run
|
259
|
+
* asynchronously to avoid Zalgo issues. Since the microtask queue is not
|
260
|
+
* exposed externally, promises need to be modified in a fairly invasive and
|
261
|
+
* complex way.
|
262
|
+
*
|
263
|
+
* The async boundary in promises that must be patched is between the
|
264
|
+
* fulfillment of the promise and the execution of any callback that is waiting
|
265
|
+
* for that fulfillment to happen. This means that we need to trigger a create
|
266
|
+
* when accept or reject is called and trigger before, after and error handlers
|
267
|
+
* around the callback execution. There may be multiple callbacks for each
|
268
|
+
* fulfilled promise, so handlers will behave similar to setInterval where
|
269
|
+
* there may be multiple before after and error calls for each create call.
|
270
|
+
*
|
271
|
+
* async-listener monkeypatching has one basic entry point: `wrapCallback`.
|
272
|
+
* `wrapCallback` should be called when create should be triggered and be
|
273
|
+
* passed a function to wrap, which will execute the body of the async work.
|
274
|
+
* The accept and reject calls can be modified fairly easily to call
|
275
|
+
* `wrapCallback`, but at the time of accept and reject all the work to be done
|
276
|
+
* on fulfillment may not be defined, since a call to then, chain or fetch can
|
277
|
+
* be made even after the promise has been fulfilled. To get around this, we
|
278
|
+
* create a placeholder function which will call a function passed into it,
|
279
|
+
* since the call to the main work is being made from within the wrapped
|
280
|
+
* function, async-listener will work correctly.
|
281
|
+
*
|
282
|
+
* There is another complication with monkeypatching Promises. Calls to then,
|
283
|
+
* chain and catch each create new Promises that are fulfilled internally in
|
284
|
+
* different ways depending on the return value of the callback. When the
|
285
|
+
* callback return a Promise, the new Promise is resolved asynchronously after
|
286
|
+
* the returned Promise has been also been resolved. When something other than
|
287
|
+
* a promise is resolved the accept call for the new Promise is put in the
|
288
|
+
* microtask queue and asynchronously resolved.
|
289
|
+
*
|
290
|
+
* Then must be wrapped so that its returned promise has a wrapper that can be
|
291
|
+
* used to invoke further continuations. This wrapper cannot be created until
|
292
|
+
* after the callback has run, since the callback may return either a promise
|
293
|
+
* or another value. Fortunately we already have a wrapper function around the
|
294
|
+
* callback we can use (the wrapper created by accept or reject).
|
295
|
+
*
|
296
|
+
* By adding an additional argument to this wrapper, we can pass in the
|
297
|
+
* returned promise so it can have its own wrapper appended. the wrapper
|
298
|
+
* function can the call the callback, and take action based on the return
|
299
|
+
* value. If a promise is returned, the new Promise can proxy the returned
|
300
|
+
* Promise's wrapper (this wrapper may not exist yet, but will by the time the
|
301
|
+
* wrapper needs to be invoked). Otherwise, a new wrapper can be create the
|
302
|
+
* same way as in accept and reject. Since this wrapper is created
|
303
|
+
* synchronously within another wrapper, it will properly appear as a
|
304
|
+
* continuation from within the callback.
|
305
|
+
*/
|
306
|
+
|
307
|
+
if (instrumentPromise) {
|
308
|
+
wrapPromise();
|
309
|
+
}
|
310
|
+
|
311
|
+
function wrapPromise() {
|
312
|
+
var Promise = global.Promise;
|
313
|
+
|
314
|
+
function wrappedPromise(executor) {
|
315
|
+
if (!(this instanceof wrappedPromise)) {
|
316
|
+
return Promise(executor);
|
317
|
+
}
|
318
|
+
|
319
|
+
if (typeof executor !== 'function') {
|
320
|
+
return new Promise(executor);
|
321
|
+
}
|
322
|
+
|
323
|
+
var context, args;
|
324
|
+
var promise = new Promise(wrappedExecutor);
|
325
|
+
promise.__proto__ = wrappedPromise.prototype;
|
326
|
+
|
327
|
+
try {
|
328
|
+
executor.apply(context, args);
|
329
|
+
} catch (err) {
|
330
|
+
args[1](err)
|
331
|
+
}
|
332
|
+
|
333
|
+
return promise;
|
334
|
+
|
335
|
+
function wrappedExecutor(accept, reject) {
|
336
|
+
context = this;
|
337
|
+
args = [wrappedAccept, wrappedReject];
|
338
|
+
|
339
|
+
// These wrappers create a function that can be passed a function and an argument to
|
340
|
+
// call as a continuation from the accept or reject.
|
341
|
+
function wrappedAccept(val) {
|
342
|
+
ensureAslWrapper(promise);
|
343
|
+
return accept(val);
|
344
|
+
}
|
345
|
+
|
346
|
+
function wrappedReject(val) {
|
347
|
+
ensureAslWrapper(promise);
|
348
|
+
return reject(val);
|
349
|
+
}
|
350
|
+
}
|
351
|
+
}
|
352
|
+
|
353
|
+
util.inherits(wrappedPromise, Promise);
|
354
|
+
|
355
|
+
wrap(Promise.prototype, 'then', wrapThen);
|
356
|
+
wrap(Promise.prototype, 'chain', wrapThen);
|
357
|
+
|
358
|
+
var PromiseMethods = ['accept', 'all', 'defer', 'race', 'reject', 'resolve'];
|
359
|
+
|
360
|
+
PromiseMethods.forEach(function(key) {
|
361
|
+
wrappedPromise[key] = Promise[key];
|
362
|
+
});
|
363
|
+
|
364
|
+
global.Promise = wrappedPromise;
|
365
|
+
|
366
|
+
function ensureAslWrapper(promise) {
|
367
|
+
if (!promise.__asl_wrapper) {
|
368
|
+
promise.__asl_wrapper = wrapCallback(propagateAslWrapper);
|
369
|
+
}
|
370
|
+
}
|
371
|
+
|
372
|
+
function propagateAslWrapper(ctx, fn, result, next) {
|
373
|
+
var nextResult;
|
374
|
+
try {
|
375
|
+
nextResult = fn.call(ctx, result);
|
376
|
+
return nextResult;
|
377
|
+
} finally {
|
378
|
+
// Wrap any resulting futures as continuations.
|
379
|
+
if (nextResult instanceof Promise) {
|
380
|
+
next.__asl_wrapper = function proxyWrapper() {
|
381
|
+
var aslWrapper = nextResult.__asl_wrapper || propagateAslWrapper;
|
382
|
+
return aslWrapper.apply(this, arguments);
|
383
|
+
}
|
384
|
+
} else {
|
385
|
+
ensureAslWrapper(next);
|
386
|
+
}
|
387
|
+
}
|
388
|
+
}
|
389
|
+
|
390
|
+
function wrapThen(original) {
|
391
|
+
return function wrappedThen() {
|
392
|
+
var promise = this;
|
393
|
+
var next = original.apply(promise, Array.prototype.map.call(arguments, bind));
|
394
|
+
return next;
|
395
|
+
|
396
|
+
// wrap callbacks (success, error) so that the callbacks will be called as a
|
397
|
+
// continuations of the accept or reject call using the __asl_wrapper created above.
|
398
|
+
function bind(fn) {
|
399
|
+
if (typeof fn !== 'function') return fn;
|
400
|
+
return function (val) {
|
401
|
+
if (!promise.__asl_wrapper) return fn.call(this, val);
|
402
|
+
return promise.__asl_wrapper(this, fn, val, next);
|
403
|
+
};
|
404
|
+
}
|
405
|
+
}
|
406
|
+
}
|
407
|
+
}
|
@@ -0,0 +1,90 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
function isFunction(funktion) {
|
4
|
+
return funktion && {}.toString.call(funktion) === '[object Function]';
|
5
|
+
}
|
6
|
+
|
7
|
+
// Default to complaining loudly when things don't go according to plan.
|
8
|
+
var logger = console.error.bind(console);
|
9
|
+
|
10
|
+
// Keep initialization idempotent.
|
11
|
+
function shimmer(options) {
|
12
|
+
if (options && options.logger) {
|
13
|
+
if (!isFunction(options.logger)) logger("new logger isn't a function, not replacing");
|
14
|
+
else logger = options.logger;
|
15
|
+
}
|
16
|
+
}
|
17
|
+
|
18
|
+
function wrap(nodule, name, wrapper) {
|
19
|
+
if (!nodule || !nodule[name]) {
|
20
|
+
logger("no original function " + name + " to wrap");
|
21
|
+
return;
|
22
|
+
}
|
23
|
+
|
24
|
+
if (!wrapper) {
|
25
|
+
logger("no wrapper function");
|
26
|
+
logger((new Error()).stack);
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
|
30
|
+
if (!isFunction(nodule[name]) || !isFunction(wrapper)) {
|
31
|
+
logger("original object and wrapper must be functions");
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
|
35
|
+
var original = nodule[name]
|
36
|
+
, wrapped = wrapper(original)
|
37
|
+
;
|
38
|
+
|
39
|
+
wrapped.__original = original;
|
40
|
+
wrapped.__unwrap = function () {
|
41
|
+
if (nodule[name] === wrapped) nodule[name] = original;
|
42
|
+
};
|
43
|
+
wrapped.__wrapped = true;
|
44
|
+
|
45
|
+
nodule[name] = wrapped;
|
46
|
+
|
47
|
+
return wrapped;
|
48
|
+
}
|
49
|
+
|
50
|
+
function massWrap(nodules, names, wrapper) {
|
51
|
+
if (!nodules) {
|
52
|
+
logger("must provide one or more modules to patch");
|
53
|
+
logger((new Error()).stack);
|
54
|
+
return;
|
55
|
+
} else if (!Array.isArray(nodules)) {
|
56
|
+
nodules = [nodules];
|
57
|
+
}
|
58
|
+
|
59
|
+
if (!(names && Array.isArray(names))) {
|
60
|
+
logger("must provide one or more functions to wrap on modules");
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
|
64
|
+
nodules.forEach(function (nodule) {
|
65
|
+
names.forEach(function (name) {
|
66
|
+
wrap(nodule, name, wrapper);
|
67
|
+
});
|
68
|
+
});
|
69
|
+
}
|
70
|
+
|
71
|
+
function unwrap(nodule, name) {
|
72
|
+
if (!nodule || !nodule[name]) {
|
73
|
+
logger("no function to unwrap.");
|
74
|
+
logger((new Error()).stack);
|
75
|
+
return;
|
76
|
+
}
|
77
|
+
|
78
|
+
if (!nodule[name].__unwrap) {
|
79
|
+
logger("no original to unwrap to -- has " + name + " already been unwrapped?");
|
80
|
+
}
|
81
|
+
else {
|
82
|
+
return nodule[name].__unwrap();
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
shimmer.wrap = wrap;
|
87
|
+
shimmer.massWrap = massWrap;
|
88
|
+
shimmer.unwrap = unwrap;
|
89
|
+
|
90
|
+
module.exports = shimmer;
|