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.

Files changed (203) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/CHANGELOG +38 -2
  5. data/CONTRIBUTORS +3 -0
  6. data/README.md +5 -1
  7. data/bin/passenger-status +2 -7
  8. data/build/agent.rb +2 -0
  9. data/build/cxx_dependency_map.rb +1464 -162
  10. data/build/node_tests.rb +1 -1
  11. data/build/packaging.rb +1 -1
  12. data/dev/ci/run_travis.sh +1 -1
  13. data/dev/vagrant/provision.sh +1 -1
  14. data/npm-shrinkwrap.json +635 -125
  15. data/package.json +1 -1
  16. data/resources/templates/standalone/config.erb +33 -161
  17. data/resources/templates/standalone/global.erb +15 -0
  18. data/resources/templates/standalone/http.erb +40 -0
  19. data/resources/templates/standalone/mass_deployment_default_server.erb +11 -0
  20. data/resources/templates/standalone/rails_asset_pipeline.erb +22 -0
  21. data/resources/templates/standalone/server.erb +58 -0
  22. data/src/agent/Core/ApiServer.h +37 -32
  23. data/src/agent/Core/ApplicationPool/BasicGroupInfo.h +1 -1
  24. data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +6 -0
  25. data/src/agent/Core/ApplicationPool/Common.h +1 -1
  26. data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
  27. data/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +4 -0
  28. data/src/agent/Core/ApplicationPool/Implementation.cpp +2 -2
  29. data/src/agent/Core/ApplicationPool/Options.h +18 -1
  30. data/src/agent/Core/ApplicationPool/Pool.h +1 -1
  31. data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +6 -6
  32. data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +3 -3
  33. data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +1 -1
  34. data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +6 -0
  35. data/src/agent/Core/ApplicationPool/Process.h +6 -1
  36. data/src/agent/Core/ApplicationPool/Socket.h +9 -12
  37. data/src/agent/Core/Controller.h +422 -0
  38. data/src/agent/Core/{RequestHandler → Controller}/AppResponse.h +2 -0
  39. data/src/agent/Core/{RequestHandler → Controller}/BufferBody.cpp +27 -5
  40. data/src/agent/Core/{RequestHandler → Controller}/CheckoutSession.cpp +61 -31
  41. data/src/agent/Core/{RequestHandler → Controller}/Client.h +5 -2
  42. data/src/agent/Core/{RequestHandler → Controller}/ForwardResponse.cpp +93 -42
  43. data/src/agent/Core/{RequestHandler → Controller}/Hooks.cpp +107 -60
  44. data/src/agent/Core/Controller/Implementation.cpp +38 -0
  45. data/src/agent/Core/{RequestHandler → Controller}/InitRequest.cpp +134 -80
  46. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +165 -0
  47. data/src/agent/Core/{RequestHandler/Utils.cpp → Controller/InternalUtils.cpp} +49 -32
  48. data/src/agent/Core/Controller/Miscellaneous.cpp +116 -0
  49. data/src/agent/Core/{RequestHandler → Controller}/Request.h +6 -4
  50. data/src/agent/Core/{RequestHandler → Controller}/SendRequest.cpp +205 -130
  51. data/src/agent/Core/Controller/StateInspectionAndConfiguration.cpp +161 -0
  52. data/src/agent/Core/{RequestHandler → Controller}/TurboCaching.h +3 -0
  53. data/src/agent/Core/CoreMain.cpp +62 -51
  54. data/src/agent/Core/OptionParser.h +24 -0
  55. data/src/agent/Core/ResponseCache.h +5 -5
  56. data/src/agent/Core/SpawningKit/Config.h +2 -2
  57. data/src/agent/Core/SpawningKit/SmartSpawner.h +1 -1
  58. data/src/agent/Core/UnionStation/{Core.h → Context.h} +14 -18
  59. data/src/agent/Core/UnionStation/StopwatchLog.h +3 -2
  60. data/src/agent/Core/UnionStation/Transaction.h +7 -7
  61. data/src/agent/Shared/ApiServerUtils.h +9 -1
  62. data/src/agent/UstRouter/ApiServer.h +5 -2
  63. data/src/agent/UstRouter/Controller.h +27 -9
  64. data/src/agent/UstRouter/UstRouterMain.cpp +1 -0
  65. data/src/agent/Watchdog/ApiServer.h +5 -2
  66. data/src/apache2_module/ConfigurationCommands.cpp +7 -0
  67. data/src/apache2_module/ConfigurationFields.hpp +2 -0
  68. data/src/apache2_module/ConfigurationSetters.cpp +24 -0
  69. data/src/apache2_module/CreateDirConfig.cpp +1 -0
  70. data/src/apache2_module/Hooks.cpp +6 -5
  71. data/src/apache2_module/MergeDirConfig.cpp +7 -0
  72. data/src/apache2_module/SetHeaders.cpp +5 -0
  73. data/src/cxx_supportlib/Constants.h +5 -3
  74. data/src/cxx_supportlib/SafeLibev.h +2 -1
  75. data/src/cxx_supportlib/UnionStationFilterSupport.h +2 -1
  76. data/src/cxx_supportlib/Utils/ReleaseableScopedPointer.h +70 -0
  77. data/src/cxx_supportlib/vendor-modified/boost/libs/regex/src/regex_raw_buffer.cpp +6 -6
  78. data/src/helper-scripts/node-loader.js +59 -0
  79. data/src/nginx_module/CacheLocationConfig.c +48 -0
  80. data/src/nginx_module/ConfigurationCommands.c +20 -0
  81. data/src/nginx_module/ConfigurationFields.h +4 -0
  82. data/src/nginx_module/CreateLocationConfig.c +8 -0
  83. data/src/nginx_module/MergeLocationConfig.c +12 -0
  84. data/src/nodejs_supportlib/phusion_passenger/log_express.js +106 -0
  85. data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +203 -0
  86. data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +227 -0
  87. data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +446 -0
  88. data/src/nodejs_supportlib/vendor-copy/codify/codify.js +44 -0
  89. data/src/nodejs_supportlib/vendor-copy/codify/package.json +29 -0
  90. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/context.js +200 -0
  91. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/glue.js +488 -0
  92. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/index.js +407 -0
  93. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/index.js +90 -0
  94. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/node_modules/shimmer/package.json +40 -0
  95. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/async-listener/package.json +54 -0
  96. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/listener.js +160 -0
  97. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/index.js +90 -0
  98. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/node_modules/shimmer/package.json +40 -0
  99. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/node_modules/emitter-listener/package.json +46 -0
  100. data/src/nodejs_supportlib/vendor-copy/continuation-local-storage/package.json +56 -0
  101. data/src/nodejs_supportlib/vendor-copy/network-byte-order/lib/index.js +102 -0
  102. data/src/nodejs_supportlib/vendor-copy/network-byte-order/package.json +51 -0
  103. data/src/nodejs_supportlib/vendor-copy/winston/LICENSE +19 -0
  104. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston.js +165 -0
  105. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/common.js +483 -0
  106. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config.js +62 -0
  107. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/cli-config.js +35 -0
  108. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/npm-config.js +27 -0
  109. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/config/syslog-config.js +31 -0
  110. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/container.js +127 -0
  111. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/exception.js +56 -0
  112. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/logger.js +701 -0
  113. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports.js +34 -0
  114. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/console.js +128 -0
  115. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/daily-rotate-file.js +601 -0
  116. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/file.js +675 -0
  117. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/http.js +232 -0
  118. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/memory.js +89 -0
  119. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/transport.js +135 -0
  120. data/src/nodejs_supportlib/vendor-copy/winston/lib/winston/transports/webhook.js +146 -0
  121. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/LICENSE +19 -0
  122. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/lib/async.js +1283 -0
  123. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/package.json +66 -0
  124. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/async/support/sync-package-managers.js +53 -0
  125. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/MIT-LICENSE.txt +23 -0
  126. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/colors.js +176 -0
  127. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/trap.js +45 -0
  128. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/custom/zalgo.js +104 -0
  129. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/extendStringPrototype.js +118 -0
  130. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/index.js +12 -0
  131. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/america.js +12 -0
  132. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/rainbow.js +13 -0
  133. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/random.js +8 -0
  134. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/maps/zebra.js +5 -0
  135. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/styles.js +77 -0
  136. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/lib/system/supports-colors.js +61 -0
  137. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/package.json +35 -0
  138. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/safe.js +9 -0
  139. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/colors/themes/generic-logging.js +12 -0
  140. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/cycle.js +170 -0
  141. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/cycle/package.json +30 -0
  142. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/LICENSE +20 -0
  143. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/lib/eyes.js +236 -0
  144. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/eyes/package.json +42 -0
  145. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/LICENSE.md +11 -0
  146. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/isstream.js +27 -0
  147. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/isstream/package.json +42 -0
  148. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/LICENSE +19 -0
  149. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/lib/pkginfo.js +136 -0
  150. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/pkginfo/package.json +56 -0
  151. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/License +19 -0
  152. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/lib/stack-trace.js +111 -0
  153. data/src/nodejs_supportlib/vendor-copy/winston/node_modules/stack-trace/package.json +33 -0
  154. data/src/nodejs_supportlib/vendor-copy/winston/package.json +87 -0
  155. data/src/ruby_supportlib/phusion_passenger.rb +3 -4
  156. data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +19 -2
  157. data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
  158. data/src/ruby_supportlib/phusion_passenger/config/list_instances_command.rb +2 -6
  159. data/src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb +13 -0
  160. data/src/ruby_supportlib/phusion_passenger/config/restart_app_command.rb +3 -0
  161. data/src/ruby_supportlib/phusion_passenger/config/utils.rb +9 -7
  162. data/src/ruby_supportlib/phusion_passenger/config/validate_install_command.rb +8 -1
  163. data/src/ruby_supportlib/phusion_passenger/constants.rb +3 -1
  164. data/src/ruby_supportlib/phusion_passenger/native_support.rb +20 -4
  165. data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +8 -0
  166. data/src/ruby_supportlib/phusion_passenger/packaging.rb +1 -0
  167. data/src/ruby_supportlib/phusion_passenger/platform_info/apache_detector.rb +1 -1
  168. data/src/ruby_supportlib/phusion_passenger/platform_info/operating_system.rb +11 -4
  169. data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +1 -1
  170. data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +647 -0
  171. data/src/ruby_supportlib/phusion_passenger/standalone/config_utils.rb +229 -15
  172. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +35 -323
  173. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +36 -12
  174. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +123 -14
  175. data/src/ruby_supportlib/phusion_passenger/standalone/status_command.rb +32 -17
  176. data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +32 -21
  177. data/src/ruby_supportlib/phusion_passenger/standalone/version_command.rb +5 -5
  178. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +2 -2
  179. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +5 -1
  180. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +68 -24
  181. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +9 -1
  182. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +9 -7
  183. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +3 -2
  184. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +8 -5
  185. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +395 -0
  186. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +10 -7
  187. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +14 -0
  188. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +2 -2
  189. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml +4 -2
  190. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +2 -2
  191. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +2 -2
  192. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +16 -0
  193. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +1 -1
  194. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +2 -2
  195. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +1 -1
  196. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +44 -17
  197. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +16 -7
  198. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +2 -2
  199. data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +1 -1
  200. metadata +99 -16
  201. metadata.gz.asc +7 -7
  202. data/resources/oss-binaries.phusionpassenger.com.crt +0 -248
  203. data/src/agent/Core/RequestHandler.h +0 -471
@@ -0,0 +1,165 @@
1
+ /*
2
+ * Phusion Passenger - https://www.phusionpassenger.com/
3
+ * Copyright (c) 2014-2015 Phusion Holding B.V.
4
+ *
5
+ * "Passenger", "Phusion Passenger" and "Union Station" are registered
6
+ * trademarks of Phusion Holding B.V.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+ #include <Core/Controller.h>
27
+
28
+ /*************************************************************************
29
+ *
30
+ * Initialization and shutdown-related code for Core::Controller
31
+ *
32
+ *************************************************************************/
33
+
34
+ namespace Passenger {
35
+ namespace Core {
36
+
37
+ using namespace std;
38
+ using namespace boost;
39
+
40
+
41
+ /****************************
42
+ *
43
+ * Public methods
44
+ *
45
+ ****************************/
46
+
47
+
48
+ Controller::Controller(ServerKit::Context *context, const VariantMap *_agentsOptions,
49
+ unsigned int _threadNumber)
50
+ : ParentClass(context),
51
+
52
+ statThrottleRate(_agentsOptions->getInt("stat_throttle_rate")),
53
+ responseBufferHighWatermark(_agentsOptions->getInt("response_buffer_high_watermark")),
54
+ benchmarkMode(parseBenchmarkMode(_agentsOptions->get("benchmark_mode", false))),
55
+ singleAppMode(false),
56
+ showVersionInHeader(_agentsOptions->getBool("show_version_in_header")),
57
+ stickySessions(_agentsOptions->getBool("sticky_sessions")),
58
+ gracefulExit(_agentsOptions->getBool("core_graceful_exit")),
59
+
60
+ agentsOptions(_agentsOptions),
61
+ stringPool(psg_create_pool(1024 * 4)),
62
+ poolOptionsCache(4),
63
+
64
+ PASSENGER_APP_GROUP_NAME("!~PASSENGER_APP_GROUP_NAME"),
65
+ PASSENGER_ENV_VARS("!~PASSENGER_ENV_VARS"),
66
+ PASSENGER_MAX_REQUESTS("!~PASSENGER_MAX_REQUESTS"),
67
+ PASSENGER_STICKY_SESSIONS("!~PASSENGER_STICKY_SESSIONS"),
68
+ PASSENGER_STICKY_SESSIONS_COOKIE_NAME("!~PASSENGER_STICKY_SESSIONS_COOKIE_NAME"),
69
+ PASSENGER_REQUEST_OOB_WORK("!~Request-OOB-Work"),
70
+ UNION_STATION_SUPPORT("!~UNION_STATION_SUPPORT"),
71
+ REMOTE_ADDR("!~REMOTE_ADDR"),
72
+ REMOTE_PORT("!~REMOTE_PORT"),
73
+ REMOTE_USER("!~REMOTE_USER"),
74
+ FLAGS("!~FLAGS"),
75
+ HTTP_COOKIE("cookie"),
76
+ HTTP_DATE("date"),
77
+ HTTP_HOST("host"),
78
+ HTTP_CONTENT_LENGTH("content-length"),
79
+ HTTP_CONTENT_TYPE("content-type"),
80
+ HTTP_EXPECT("expect"),
81
+ HTTP_CONNECTION("connection"),
82
+ HTTP_STATUS("status"),
83
+ HTTP_TRANSFER_ENCODING("transfer-encoding"),
84
+
85
+ threadNumber(_threadNumber),
86
+ turboCaching(getTurboCachingInitialState(_agentsOptions))
87
+ {
88
+ defaultRuby = psg_pstrdup(stringPool,
89
+ agentsOptions->get("default_ruby"));
90
+ ustRouterAddress = psg_pstrdup(stringPool,
91
+ agentsOptions->get("ust_router_address", false));
92
+ ustRouterPassword = psg_pstrdup(stringPool,
93
+ agentsOptions->get("ust_router_password", false));
94
+ defaultUser = psg_pstrdup(stringPool,
95
+ agentsOptions->get("default_user", false));
96
+ defaultGroup = psg_pstrdup(stringPool,
97
+ agentsOptions->get("default_group", false));
98
+ defaultServerName = psg_pstrdup(stringPool,
99
+ agentsOptions->get("default_server_name"));
100
+ defaultServerPort = psg_pstrdup(stringPool,
101
+ agentsOptions->get("default_server_port"));
102
+ serverSoftware = psg_pstrdup(stringPool,
103
+ agentsOptions->get("server_software"));
104
+ defaultStickySessionsCookieName = psg_pstrdup(stringPool,
105
+ agentsOptions->get("sticky_sessions_cookie_name"));
106
+
107
+ if (agentsOptions->has("vary_turbocache_by_cookie")) {
108
+ defaultVaryTurbocacheByCookie = psg_pstrdup(stringPool,
109
+ agentsOptions->get("vary_turbocache_by_cookie"));
110
+ }
111
+
112
+ generateServerLogName(_threadNumber);
113
+
114
+ if (!agentsOptions->getBool("multi_app")) {
115
+ boost::shared_ptr<Options> options = boost::make_shared<Options>();
116
+
117
+ singleAppMode = true;
118
+ fillPoolOptionsFromAgentsOptions(*options);
119
+
120
+ options->appRoot = psg_pstrdup(stringPool,
121
+ agentsOptions->get("app_root"));
122
+ options->environment = psg_pstrdup(stringPool,
123
+ agentsOptions->get("environment"));
124
+ options->appType = psg_pstrdup(stringPool,
125
+ agentsOptions->get("app_type"));
126
+ options->startupFile = psg_pstrdup(stringPool,
127
+ agentsOptions->get("startup_file"));
128
+ poolOptionsCache.insert(options->getAppGroupName(), options);
129
+ }
130
+
131
+ ev_check_init(&checkWatcher, onEventLoopCheck);
132
+ ev_set_priority(&checkWatcher, EV_MAXPRI);
133
+ ev_check_start(getLoop(), &checkWatcher);
134
+ checkWatcher.data = this;
135
+
136
+ #ifdef DEBUG_CC_EVENT_LOOP_BLOCKING
137
+ ev_prepare_init(&prepareWatcher, onEventLoopPrepare);
138
+ ev_prepare_start(getLoop(), &prepareWatcher);
139
+ prepareWatcher.data = this;
140
+
141
+ timeBeforeBlocking = 0;
142
+ #endif
143
+ }
144
+
145
+ Controller::~Controller() {
146
+ psg_destroy_pool(stringPool);
147
+ }
148
+
149
+ void
150
+ Controller::initialize() {
151
+ TRACE_POINT();
152
+ if (resourceLocator == NULL) {
153
+ throw RuntimeException("ResourceLocator not initialized");
154
+ }
155
+ if (appPool == NULL) {
156
+ throw RuntimeException("AppPool not initialized");
157
+ }
158
+ if (unionStationContext == NULL) {
159
+ unionStationContext = appPool->getUnionStationContext();
160
+ }
161
+ }
162
+
163
+
164
+ } // namespace Core
165
+ } // namespace Passenger
@@ -23,21 +23,30 @@
23
23
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
24
  * THE SOFTWARE.
25
25
  */
26
+ #include <Core/Controller.h>
26
27
 
27
- // This file is included inside the RequestHandler class.
28
+ /*************************************************************************
29
+ *
30
+ * Internal utility functions for Core::Controller
31
+ *
32
+ *************************************************************************/
33
+
34
+ namespace Passenger {
35
+ namespace Core {
28
36
 
29
- #define RH_BENCHMARK_POINT(client, req, value) \
30
- do { \
31
- if (OXT_UNLIKELY(benchmarkMode == value)) { \
32
- writeBenchmarkResponse(&client, &req); \
33
- return; \
34
- } \
35
- } while (false)
37
+ using namespace std;
38
+ using namespace boost;
39
+
40
+
41
+ /****************************
42
+ *
43
+ * Private methods
44
+ *
45
+ ****************************/
36
46
 
37
- private:
38
47
 
39
- static TurboCaching<Request>::State
40
- getTurboCachingInitialState(const VariantMap *agentsOptions) {
48
+ TurboCaching<Request>::State
49
+ Controller::getTurboCachingInitialState(const VariantMap *agentsOptions) {
41
50
  bool enabled = agentsOptions->getBool("turbocaching", false, true);
42
51
  if (enabled) {
43
52
  return TurboCaching<Request>::ENABLED;
@@ -47,13 +56,13 @@ getTurboCachingInitialState(const VariantMap *agentsOptions) {
47
56
  }
48
57
 
49
58
  void
50
- generateServerLogName(unsigned int number) {
59
+ Controller::generateServerLogName(unsigned int number) {
51
60
  string name = "ServerThr." + toString(number);
52
61
  serverLogName = psg_pstrdup(stringPool, name);
53
62
  }
54
63
 
55
64
  void
56
- disconnectWithClientSocketWriteError(Client **client, int e) {
65
+ Controller::disconnectWithClientSocketWriteError(Client **client, int e) {
57
66
  stringstream message;
58
67
  PassengerLogLevel logLevel;
59
68
  message << "client socket write error: ";
@@ -68,12 +77,12 @@ disconnectWithClientSocketWriteError(Client **client, int e) {
68
77
  }
69
78
 
70
79
  void
71
- disconnectWithAppSocketIncompleteResponseError(Client **client) {
80
+ Controller::disconnectWithAppSocketIncompleteResponseError(Client **client) {
72
81
  disconnectWithError(client, "application did not send a complete response");
73
82
  }
74
83
 
75
84
  void
76
- disconnectWithAppSocketReadError(Client **client, int e) {
85
+ Controller::disconnectWithAppSocketReadError(Client **client, int e) {
77
86
  stringstream message;
78
87
  message << "app socket read error: ";
79
88
  message << ServerKit::getErrorDesc(e);
@@ -82,7 +91,7 @@ disconnectWithAppSocketReadError(Client **client, int e) {
82
91
  }
83
92
 
84
93
  void
85
- disconnectWithAppSocketWriteError(Client **client, int e) {
94
+ Controller::disconnectWithAppSocketWriteError(Client **client, int e) {
86
95
  stringstream message;
87
96
  message << "app socket write error: ";
88
97
  message << ServerKit::getErrorDesc(e);
@@ -91,7 +100,7 @@ disconnectWithAppSocketWriteError(Client **client, int e) {
91
100
  }
92
101
 
93
102
  void
94
- endRequestWithAppSocketIncompleteResponse(Client **client, Request **req) {
103
+ Controller::endRequestWithAppSocketIncompleteResponse(Client **client, Request **req) {
95
104
  if (!(*req)->responseBegun) {
96
105
  SKC_WARN(*client, "Sending 502 response: application did not send a complete response");
97
106
  endRequestWithSimpleResponse(client, req,
@@ -102,7 +111,7 @@ endRequestWithAppSocketIncompleteResponse(Client **client, Request **req) {
102
111
  }
103
112
 
104
113
  void
105
- endRequestWithAppSocketReadError(Client **client, Request **req, int e) {
114
+ Controller::endRequestWithAppSocketReadError(Client **client, Request **req, int e) {
106
115
  Client *c = *client;
107
116
  if (!(*req)->responseBegun) {
108
117
  SKC_WARN(*client, "Sending 502 response: application socket read error");
@@ -116,7 +125,9 @@ endRequestWithAppSocketReadError(Client **client, Request **req, int e) {
116
125
  * `data` must outlive the request.
117
126
  */
118
127
  void
119
- endRequestWithSimpleResponse(Client **c, Request **r, const StaticString &body, int code = 200) {
128
+ Controller::endRequestWithSimpleResponse(Client **c, Request **r,
129
+ const StaticString &body, int code)
130
+ {
120
131
  Client *client = *c;
121
132
  Request *req = *r;
122
133
  ServerKit::HeaderTable headers;
@@ -127,7 +138,7 @@ endRequestWithSimpleResponse(Client **c, Request **r, const StaticString &body,
127
138
  }
128
139
 
129
140
  void
130
- endRequestAsBadGateway(Client **client, Request **req) {
141
+ Controller::endRequestAsBadGateway(Client **client, Request **req) {
131
142
  if ((*req)->responseBegun) {
132
143
  disconnectWithError(client, "bad gateway");
133
144
  } else {
@@ -139,7 +150,7 @@ endRequestAsBadGateway(Client **client, Request **req) {
139
150
  }
140
151
 
141
152
  void
142
- writeBenchmarkResponse(Client **client, Request **req, bool end = true) {
153
+ Controller::writeBenchmarkResponse(Client **client, Request **req, bool end) {
143
154
  if (canKeepAlive(*req)) {
144
155
  writeResponse(*client, P_STATIC_STRING(
145
156
  "HTTP/1.1 200 OK\r\n"
@@ -167,7 +178,9 @@ writeBenchmarkResponse(Client **client, Request **req, bool end = true) {
167
178
  }
168
179
 
169
180
  bool
170
- getBoolOption(Request *req, const HashedStaticString &name, bool defaultValue = false) {
181
+ Controller::getBoolOption(Request *req, const HashedStaticString &name,
182
+ bool defaultValue)
183
+ {
171
184
  const LString *value = req->secureHeaders.lookup(name);
172
185
  if (value != NULL && value->size > 0) {
173
186
  return psg_lstr_first_byte(value) == 't';
@@ -177,14 +190,14 @@ getBoolOption(Request *req, const HashedStaticString &name, bool defaultValue =
177
190
  }
178
191
 
179
192
  template<typename Number>
180
- static Number
181
- clamp(Number value, Number min, Number max) {
193
+ Number
194
+ Controller::clamp(Number value, Number min, Number max) {
182
195
  return std::max(std::min(value, max), min);
183
196
  }
184
197
 
185
- static void
186
- gatherBuffers(char * restrict dest, unsigned int size, const struct iovec *buffers,
187
- unsigned int nbuffers)
198
+ void
199
+ Controller::gatherBuffers(char * restrict dest, unsigned int size,
200
+ const struct iovec *buffers, unsigned int nbuffers)
188
201
  {
189
202
  const char *end = dest + size;
190
203
  char *pos = dest;
@@ -197,8 +210,8 @@ gatherBuffers(char * restrict dest, unsigned int size, const struct iovec *buffe
197
210
  }
198
211
 
199
212
  // `path` MUST be NULL-terminated. Returns a contiguous LString.
200
- static LString *
201
- resolveSymlink(const StaticString &path, psg_pool_t *pool) {
213
+ LString *
214
+ Controller::resolveSymlink(const StaticString &path, psg_pool_t *pool) {
202
215
  char linkbuf[PATH_MAX + 1];
203
216
  ssize_t size;
204
217
 
@@ -250,7 +263,7 @@ resolveSymlink(const StaticString &path, psg_pool_t *pool) {
250
263
  }
251
264
 
252
265
  void
253
- parseCookieHeader(psg_pool_t *pool, const LString *headerValue,
266
+ Controller::parseCookieHeader(psg_pool_t *pool, const LString *headerValue,
254
267
  vector< pair<StaticString, StaticString> > &cookies) const
255
268
  {
256
269
  // See http://stackoverflow.com/questions/6108207/definite-guide-to-valid-cookie-values
@@ -291,9 +304,9 @@ parseCookieHeader(psg_pool_t *pool, const LString *headerValue,
291
304
  }
292
305
  }
293
306
 
294
- #ifdef DEBUG_RH_EVENT_LOOP_BLOCKING
307
+ #ifdef DEBUG_CC_EVENT_LOOP_BLOCKING
295
308
  void
296
- reportLargeTimeDiff(Client *client, const char *name,
309
+ Controller::reportLargeTimeDiff(Client *client, const char *name,
297
310
  ev_tstamp fromTime, ev_tstamp toTime)
298
311
  {
299
312
  if (fromTime != 0 && toTime != 0) {
@@ -311,3 +324,7 @@ parseCookieHeader(psg_pool_t *pool, const LString *headerValue,
311
324
  }
312
325
  }
313
326
  #endif
327
+
328
+
329
+ } // namespace Core
330
+ } // namespace Passenger
@@ -0,0 +1,116 @@
1
+ /*
2
+ * Phusion Passenger - https://www.phusionpassenger.com/
3
+ * Copyright (c) 2014-2015 Phusion Holding B.V.
4
+ *
5
+ * "Passenger", "Phusion Passenger" and "Union Station" are registered
6
+ * trademarks of Phusion Holding B.V.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+ #include <Core/Controller.h>
27
+
28
+ /*************************************************************************
29
+ *
30
+ * Miscellaneous functions for Core::Controller
31
+ *
32
+ *************************************************************************/
33
+
34
+ namespace Passenger {
35
+ namespace Core {
36
+
37
+ using namespace std;
38
+ using namespace boost;
39
+
40
+
41
+ /****************************
42
+ *
43
+ * Public methods
44
+ *
45
+ ****************************/
46
+
47
+
48
+ void
49
+ Controller::disconnectLongRunningConnections(const StaticString &gupid) {
50
+ vector<Client *> clients;
51
+ vector<Client *>::iterator v_it, v_end;
52
+ Client *client;
53
+
54
+ // We collect all clients in a vector so that we don't have to worry about
55
+ // `activeClients` being mutated while we work.
56
+ TAILQ_FOREACH (client, &activeClients, nextClient.activeOrDisconnectedClient) {
57
+ P_ASSERT_EQ(client->getConnState(), Client::ACTIVE);
58
+ if (client->currentRequest != NULL) {
59
+ Request *req = client->currentRequest;
60
+ if (req->httpState >= Request::COMPLETE
61
+ && req->upgraded()
62
+ && req->options.abortWebsocketsOnProcessShutdown
63
+ && req->session != NULL
64
+ && req->session->getGupid() == gupid)
65
+ {
66
+ if (getLogLevel() >= LVL_INFO) {
67
+ char clientName[32];
68
+ unsigned int size;
69
+ const LString *host;
70
+ StaticString hostStr;
71
+
72
+ size = getClientName(client, clientName, sizeof(clientName));
73
+ if (req->host != NULL && req->host->size > 0) {
74
+ host = psg_lstr_make_contiguous(req->host, req->pool);
75
+ hostStr = StaticString(host->start->data, host->size);
76
+ }
77
+ P_INFO("[" << getServerName() << "] Disconnecting client " <<
78
+ StaticString(clientName, size) << ": " <<
79
+ hostStr << StaticString(req->path.start->data, req->path.size));
80
+ }
81
+ refClient(client, __FILE__, __LINE__);
82
+ clients.push_back(client);
83
+ }
84
+ }
85
+ }
86
+
87
+ // Disconnect each eligible client.
88
+ v_end = clients.end();
89
+ for (v_it = clients.begin(); v_it != v_end; v_it++) {
90
+ client = *v_it;
91
+ Client *c = client;
92
+ disconnect(&client);
93
+ unrefClient(c, __FILE__, __LINE__);
94
+ }
95
+ }
96
+
97
+ Controller::BenchmarkMode
98
+ Controller::parseBenchmarkMode(const StaticString mode) {
99
+ if (mode.empty()) {
100
+ return BM_NONE;
101
+ } else if (mode == "after_accept") {
102
+ return BM_AFTER_ACCEPT;
103
+ } else if (mode == "before_checkout") {
104
+ return BM_BEFORE_CHECKOUT;
105
+ } else if (mode == "after_checkout") {
106
+ return BM_AFTER_CHECKOUT;
107
+ } else if (mode == "response_begin") {
108
+ return BM_RESPONSE_BEGIN;
109
+ } else {
110
+ return BM_UNKNOWN;
111
+ }
112
+ }
113
+
114
+
115
+ } // namespace Core
116
+ } // namespace Passenger