MCPcopy Create free account
hub / github.com/apache/httpd / ap_add_cgi_vars

Function ap_add_cgi_vars

server/util_script.c:401–470  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

399}
400
401AP_DECLARE(void) ap_add_cgi_vars(request_rec *r)
402{
403 apr_table_t *e = r->subprocess_env;
404 core_dir_config *conf =
405 (core_dir_config *)ap_get_core_module_config(r->per_dir_config);
406 int request_uri_from_original = 1;
407 const char *request_uri_rule;
408
409 apr_table_setn(e, "GATEWAY_INTERFACE", "CGI/1.1");
410 apr_table_setn(e, "SERVER_PROTOCOL", r->protocol);
411 apr_table_setn(e, "REQUEST_METHOD", r->method);
412 apr_table_setn(e, "QUERY_STRING", r->args ? r->args : "");
413
414 if (conf->cgi_var_rules) {
415 request_uri_rule = apr_hash_get(conf->cgi_var_rules, "REQUEST_URI",
416 APR_HASH_KEY_STRING);
417 if (request_uri_rule && !strcmp(request_uri_rule, "current-uri")) {
418 request_uri_from_original = 0;
419 }
420 }
421 apr_table_setn(e, "REQUEST_URI",
422 request_uri_from_original ? original_uri(r) : r->uri);
423
424 /* Note that the code below special-cases scripts run from includes,
425 * because it "knows" that the sub_request has been hacked to have the
426 * args and path_info of the original request, and not any that may have
427 * come with the script URI in the include command. Ugh.
428 */
429
430 if (!strcmp(r->protocol, "INCLUDED")) {
431 apr_table_setn(e, "SCRIPT_NAME", r->uri);
432 if (r->path_info && *r->path_info) {
433 apr_table_setn(e, "PATH_INFO", r->path_info);
434 }
435 }
436 else if (!r->path_info || !*r->path_info) {
437 apr_table_setn(e, "SCRIPT_NAME", r->uri);
438 }
439 else {
440 int path_info_start = ap_find_path_info(r->uri, r->path_info);
441
442 apr_table_setn(e, "SCRIPT_NAME",
443 apr_pstrndup(r->pool, r->uri, path_info_start));
444
445 apr_table_setn(e, "PATH_INFO", r->path_info);
446 }
447
448 if (r->path_info && r->path_info[0]) {
449 /*
450 * To get PATH_TRANSLATED, treat PATH_INFO as a URI path.
451 * Need to re-escape it for this, since the entire URI was
452 * un-escaped before we determined where the PATH_INFO began.
453 */
454 request_rec *pa_req;
455
456 pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info), r,
457 NULL);
458

Callers 10

isapi_handlerFunction · 0.85
setupenvFunction · 0.85
send_environmentFunction · 0.85
uwsgi_send_headersFunction · 0.85
send_headersFunction · 0.85
cgid_handlerFunction · 0.85
cgi_handlerFunction · 0.85
includes_filterFunction · 0.85
init_ext_filter_processFunction · 0.85
util_script.hFile · 0.85

Calls 5

original_uriFunction · 0.85
ap_find_path_infoFunction · 0.85
ap_sub_req_lookup_uriFunction · 0.85
ap_destroy_sub_reqFunction · 0.85

Tested by

no test coverage detected