handle http globals being set

Signed-off-by: Robert Landers <landers.robert@gmail.com>
This commit is contained in:
Robert Landers
2025-08-10 16:37:09 +02:00
parent 0fe497e3e7
commit 09cf8a6fda
3 changed files with 20 additions and 3 deletions

2
cgi.go
View File

@@ -7,6 +7,7 @@ package frankenphp
// #cgo noescape frankenphp_register_bulk
// #cgo noescape frankenphp_register_variables_from_request_info
// #cgo noescape frankenphp_register_variable_safe
// #cgo noescape frankenphp_register_env_safe
// #cgo noescape frankenphp_register_single
// #include <php_variables.h>
// #include "frankenphp.h"
@@ -195,6 +196,7 @@ func addHeadersToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
func addPreparedEnvToServer(fc *frankenPHPContext, trackVarsArray *C.zval) {
for k, v := range fc.env {
C.frankenphp_register_variable_safe(toUnsafeChar(k), toUnsafeChar(v), C.size_t(len(v)), trackVarsArray)
C.frankenphp_register_env_safe(toUnsafeChar(k), toUnsafeChar(v), C.size_t(len(v)))
}
fc.env = nil
}

View File

@@ -748,6 +748,17 @@ void frankenphp_register_variable_safe(char *key, char *val, size_t val_len,
}
}
void frankenphp_register_env_safe(char *key, char *val, size_t val_len) {
bool should_filter_var = sapi_module.input_filter != NULL;
size_t new_val_len = val_len;
if (!should_filter_var ||
sapi_module.input_filter(PARSE_ENV, key, &val, new_val_len,
&new_val_len)) {
php_register_variable_safe(key, val, new_val_len,
&PG(http_globals)[TRACK_VARS_ENV]);
}
}
static inline void register_server_variable_filtered(const char *key,
char **val,
size_t *val_len,
@@ -764,13 +775,13 @@ static void frankenphp_register_variables(zval *track_vars_array) {
* variables.
*/
zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_ENV]);
array_init(&PG(http_globals)[TRACK_VARS_ENV]);
zval_ptr_dtor_nogc(&PG(http_globals)[TRACK_VARS_ENV]);
array_init(&PG(http_globals)[TRACK_VARS_ENV]);
/* in non-worker mode we import the os environment regularly */
if (!is_worker_thread) {
get_full_env(track_vars_array);
// php_import_environment_variables(track_vars_array);
get_full_env(&PG(http_globals)[TRACK_VARS_ENV]);
go_register_variables(thread_index, track_vars_array);
return;
}
@@ -789,6 +800,8 @@ static void frankenphp_register_variables(zval *track_vars_array) {
}
zend_hash_copy(Z_ARR_P(track_vars_array), Z_ARR_P(os_environment),
(copy_ctor_func_t)zval_add_ref);
zend_hash_copy(Z_ARR_P(&PG(http_globals)[TRACK_VARS_ENV]),
Z_ARR_P(os_environment), (copy_ctor_func_t)zval_add_ref);
go_register_variables(thread_index, track_vars_array);
}

View File

@@ -71,6 +71,8 @@ void frankenphp_register_variables_from_request_info(
zend_string *auth_user, zend_string *request_method);
void frankenphp_register_variable_safe(char *key, char *var, size_t val_len,
zval *track_vars_array);
void frankenphp_register_env_safe(char *key, char *var, size_t val_len);
zend_string *frankenphp_init_persistent_string(const char *string, size_t len);
int frankenphp_reset_opcache(void);
int frankenphp_get_current_memory_limit();