Klaus Demo nginx / d56088f
fastcgi_pass variables support Igor Sysoev 13 years ago
1 changed file(s) with 100 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
1818 ngx_array_t *params;
1919 ngx_array_t *params_source;
2020 ngx_array_t *catch_stderr;
21
22 ngx_array_t *fastcgi_lengths;
23 ngx_array_t *fastcgi_values;
2124 } ngx_http_fastcgi_loc_conf_t;
2225
2326
102105 } ngx_http_fastcgi_request_start_t;
103106
104107
108 static ngx_int_t ngx_http_fastcgi_eval(ngx_http_request_t *r,
109 ngx_http_fastcgi_loc_conf_t *flcf);
105110 static ngx_int_t ngx_http_fastcgi_create_request(ngx_http_request_t *r);
106111 static ngx_int_t ngx_http_fastcgi_reinit_request(ngx_http_request_t *r);
107112 static ngx_int_t ngx_http_fastcgi_process_header(ngx_http_request_t *r);
413418 return NGX_HTTP_INTERNAL_SERVER_ERROR;
414419 }
415420
416 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
417
418421 u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t));
419422 if (u == NULL) {
420423 return NGX_HTTP_INTERNAL_SERVER_ERROR;
421424 }
422425
423 u->schema = flcf->upstream.schema;
426 r->upstream = u;
427
428 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module);
429
430 if (flcf->fastcgi_lengths) {
431 if (ngx_http_fastcgi_eval(r, flcf) != NGX_OK) {
432 return NGX_HTTP_INTERNAL_SERVER_ERROR;
433 }
434 }
435
436 u->schema.len = sizeof("fastcgi://") - 1;
437 u->schema.data = (u_char *) "fastcgi://";
424438
425439 u->peer.log = r->connection->log;
426440 u->peer.log_error = NGX_ERROR_ERR;
448462 u->pipe->input_filter = ngx_http_fastcgi_input_filter;
449463 u->pipe->input_ctx = r;
450464
451 r->upstream = u;
452
453465 rc = ngx_http_read_client_request_body(r, ngx_http_upstream_init);
454466
455467 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
457469 }
458470
459471 return NGX_DONE;
472 }
473
474
475 static ngx_int_t
476 ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)
477 {
478 ngx_url_t u;
479
480 ngx_memzero(&u, sizeof(ngx_url_t));
481
482 if (ngx_http_script_run(r, &u.url, flcf->fastcgi_lengths->elts, 0,
483 flcf->fastcgi_values->elts)
484 == NULL)
485 {
486 return NGX_ERROR;
487 }
488
489 u.no_resolve = 1;
490
491 if (ngx_parse_url(r->pool, &u) != NGX_OK) {
492 if (u.err) {
493 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
494 "%s in upstream \"%V\"", u.err, &u.url);
495 }
496
497 return NGX_ERROR;
498 }
499
500 r->upstream->resolved = ngx_pcalloc(r->pool,
501 sizeof(ngx_http_upstream_resolved_t));
502 if (r->upstream->resolved == NULL) {
503 return NGX_ERROR;
504 }
505
506 r->upstream->resolved->host = u.host;
507 r->upstream->resolved->port = u.port;
508
509 return NGX_OK;
460510 }
461511
462512
18631913 conf->upstream.schema = prev->upstream.schema;
18641914 }
18651915
1916 if (conf->fastcgi_lengths == NULL) {
1917 conf->fastcgi_lengths = prev->fastcgi_lengths;
1918 conf->fastcgi_values = prev->fastcgi_values;
1919 }
1920
18661921 if (conf->params_source == NULL) {
18671922 conf->flushes = prev->flushes;
18681923 conf->params_len = prev->params_len;
20432098 static char *
20442099 ngx_http_fastcgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
20452100 {
2046 ngx_http_fastcgi_loc_conf_t *lcf = conf;
2047
2048 ngx_url_t u;
2049 ngx_str_t *value;
2050 ngx_http_core_loc_conf_t *clcf;
2051
2052 if (lcf->upstream.schema.len) {
2101 ngx_http_fastcgi_loc_conf_t *flcf = conf;
2102
2103 ngx_url_t u;
2104 ngx_str_t *value, *url;
2105 ngx_uint_t n;
2106 ngx_http_core_loc_conf_t *clcf;
2107 ngx_http_script_compile_t sc;
2108
2109 if (flcf->upstream.schema.len) {
20532110 return "is duplicate";
20542111 }
20552112
2113 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
2114 clcf->handler = ngx_http_fastcgi_handler;
2115
2116 flcf->upstream.schema.len = sizeof("fastcgi://") - 1;
2117 flcf->upstream.schema.data = (u_char *) "fastcgi://";
2118
20562119 value = cf->args->elts;
2120
2121 url = &value[1];
2122
2123 n = ngx_http_script_variables_count(url);
2124
2125 if (n) {
2126
2127 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t));
2128
2129 sc.cf = cf;
2130 sc.source = url;
2131 sc.lengths = &flcf->fastcgi_lengths;
2132 sc.values = &flcf->fastcgi_values;
2133 sc.variables = n;
2134 sc.complete_lengths = 1;
2135 sc.complete_values = 1;
2136
2137 if (ngx_http_script_compile(&sc) != NGX_OK) {
2138 return NGX_CONF_ERROR;
2139 }
2140
2141 return NGX_CONF_OK;
2142 }
20572143
20582144 ngx_memzero(&u, sizeof(ngx_url_t));
20592145
20602146 u.url = value[1];
20612147 u.no_resolve = 1;
20622148
2063 lcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
2064 if (lcf->upstream.upstream == NULL) {
2149 flcf->upstream.upstream = ngx_http_upstream_add(cf, &u, 0);
2150 if (flcf->upstream.upstream == NULL) {
20652151 return NGX_CONF_ERROR;
20662152 }
2067
2068 lcf->upstream.schema.len = sizeof("fastcgi://") - 1;
2069 lcf->upstream.schema.data = (u_char *) "fastcgi://";
2070
2071 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
2072
2073 clcf->handler = ngx_http_fastcgi_handler;
20742153
20752154 if (clcf->name.data[clcf->name.len - 1] == '/') {
20762155 clcf->auto_redirect = 1;