@@ -139,6 +139,12 @@ static void node_php_embed_send_header(sapi_header_struct *sapi_header,
139139 TRACE (" <" );
140140}
141141
142+ static char * node_php_embed_read_cookies (TSRMLS_D) {
143+ // This is a hack to prevent the SAPI from overwriting the
144+ // cookie data we set up in the PhpRequestWorker constructor.
145+ return SG (request_info).cookie_data ;
146+ }
147+
142148static void node_php_embed_register_server_variables (
143149 zval *track_vars_array TSRMLS_DC) {
144150 TRACE (" >" );
@@ -275,15 +281,7 @@ static void node_php_embed_ensure_init(void) {
275281 // Shutdown the initially-created request; we'll create our own request
276282 // objects inside PhpRequestWorker.
277283 php_request_shutdown (nullptr );
278- #define CHECK_NULL (requestvar ) \
279- if (SG (request_info).requestvar ) { \
280- NPE_ERROR (" OOPS! " #requestvar " is set!" ); \
281- SG (request_info).requestvar = nullptr ; \
282- }
283- CHECK_NULL (request_method);
284- CHECK_NULL (query_string);
285- CHECK_NULL (path_translated);
286- CHECK_NULL (request_uri);
284+ PhpRequestWorker::CheckRequestInfo (TSRMLS_C);
287285 node::AtExit (ModuleShutdown, nullptr );
288286 TRACE (" <" );
289287}
@@ -294,10 +292,13 @@ NAN_MODULE_INIT(ModuleInit) {
294292 php_embed_module.php_ini_ignore = true ;
295293 php_embed_module.php_ini_ignore_cwd = true ;
296294 php_embed_module.ini_defaults = nullptr ;
295+ // The following initialization statements are kept in the same
296+ // order as the fields in `struct _sapi_module_struct` (SAPI.h)
297297 php_embed_module.startup = node_php_embed_startup;
298- php_embed_module.send_header = node_php_embed_send_header;
299298 php_embed_module.ub_write = node_php_embed_ub_write;
300299 php_embed_module.flush = node_php_embed_flush;
300+ php_embed_module.send_header = node_php_embed_send_header;
301+ php_embed_module.read_cookies = node_php_embed_read_cookies;
301302 php_embed_module.register_server_variables =
302303 node_php_embed_register_server_variables;
303304 // Most of init will be done lazily in node_php_embed_ensure_init()
0 commit comments