Mercurial > hg > nginx
comparison src/http/modules/ngx_http_scgi_module.c @ 4277:e4b8255e44c3
Separate functions to merge fastcgi/scgi/uwsgi params.
No functional changes.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 14 Nov 2011 13:24:43 +0000 |
parents | 9d59a8eda373 |
children | f57229cba7ad |
comparison
equal
deleted
inserted
replaced
4276:a0f18c78db3b | 4277:e4b8255e44c3 |
---|---|
41 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc); | 41 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc); |
42 | 42 |
43 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); | 43 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); |
44 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, | 44 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, |
45 void *child); | 45 void *child); |
46 static ngx_int_t ngx_http_scgi_merge_params(ngx_conf_t *cf, | |
47 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_loc_conf_t *prev); | |
46 | 48 |
47 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 49 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
48 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, | 50 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, |
49 void *conf); | 51 void *conf); |
50 | 52 |
1057 ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | 1059 ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |
1058 { | 1060 { |
1059 ngx_http_scgi_loc_conf_t *prev = parent; | 1061 ngx_http_scgi_loc_conf_t *prev = parent; |
1060 ngx_http_scgi_loc_conf_t *conf = child; | 1062 ngx_http_scgi_loc_conf_t *conf = child; |
1061 | 1063 |
1064 size_t size; | |
1065 ngx_hash_init_t hash; | |
1066 ngx_http_core_loc_conf_t *clcf; | |
1067 | |
1068 if (conf->upstream.store != 0) { | |
1069 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0); | |
1070 | |
1071 if (conf->upstream.store_lengths == NULL) { | |
1072 conf->upstream.store_lengths = prev->upstream.store_lengths; | |
1073 conf->upstream.store_values = prev->upstream.store_values; | |
1074 } | |
1075 } | |
1076 | |
1077 ngx_conf_merge_uint_value(conf->upstream.store_access, | |
1078 prev->upstream.store_access, 0600); | |
1079 | |
1080 ngx_conf_merge_value(conf->upstream.buffering, | |
1081 prev->upstream.buffering, 1); | |
1082 | |
1083 ngx_conf_merge_value(conf->upstream.ignore_client_abort, | |
1084 prev->upstream.ignore_client_abort, 0); | |
1085 | |
1086 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, | |
1087 prev->upstream.connect_timeout, 60000); | |
1088 | |
1089 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
1090 prev->upstream.send_timeout, 60000); | |
1091 | |
1092 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
1093 prev->upstream.read_timeout, 60000); | |
1094 | |
1095 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
1096 prev->upstream.send_lowat, 0); | |
1097 | |
1098 ngx_conf_merge_size_value(conf->upstream.buffer_size, | |
1099 prev->upstream.buffer_size, | |
1100 (size_t) ngx_pagesize); | |
1101 | |
1102 | |
1103 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
1104 8, ngx_pagesize); | |
1105 | |
1106 if (conf->upstream.bufs.num < 2) { | |
1107 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1108 "there must be at least 2 \"scgi_buffers\""); | |
1109 return NGX_CONF_ERROR; | |
1110 } | |
1111 | |
1112 | |
1113 size = conf->upstream.buffer_size; | |
1114 if (size < conf->upstream.bufs.size) { | |
1115 size = conf->upstream.bufs.size; | |
1116 } | |
1117 | |
1118 | |
1119 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, | |
1120 prev->upstream.busy_buffers_size_conf, | |
1121 NGX_CONF_UNSET_SIZE); | |
1122 | |
1123 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { | |
1124 conf->upstream.busy_buffers_size = 2 * size; | |
1125 } else { | |
1126 conf->upstream.busy_buffers_size = | |
1127 conf->upstream.busy_buffers_size_conf; | |
1128 } | |
1129 | |
1130 if (conf->upstream.busy_buffers_size < size) { | |
1131 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1132 "\"scgi_busy_buffers_size\" must be equal or bigger " | |
1133 "than maximum of the value of \"scgi_buffer_size\" and " | |
1134 "one of the \"scgi_buffers\""); | |
1135 | |
1136 return NGX_CONF_ERROR; | |
1137 } | |
1138 | |
1139 if (conf->upstream.busy_buffers_size | |
1140 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
1141 { | |
1142 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1143 "\"scgi_busy_buffers_size\" must be less than " | |
1144 "the size of all \"scgi_buffers\" minus one buffer"); | |
1145 | |
1146 return NGX_CONF_ERROR; | |
1147 } | |
1148 | |
1149 | |
1150 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, | |
1151 prev->upstream.temp_file_write_size_conf, | |
1152 NGX_CONF_UNSET_SIZE); | |
1153 | |
1154 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { | |
1155 conf->upstream.temp_file_write_size = 2 * size; | |
1156 } else { | |
1157 conf->upstream.temp_file_write_size = | |
1158 conf->upstream.temp_file_write_size_conf; | |
1159 } | |
1160 | |
1161 if (conf->upstream.temp_file_write_size < size) { | |
1162 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1163 "\"scgi_temp_file_write_size\" must be equal or bigger than " | |
1164 "maximum of the value of \"scgi_buffer_size\" and " | |
1165 "one of the \"scgi_buffers\""); | |
1166 | |
1167 return NGX_CONF_ERROR; | |
1168 } | |
1169 | |
1170 | |
1171 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, | |
1172 prev->upstream.max_temp_file_size_conf, | |
1173 NGX_CONF_UNSET_SIZE); | |
1174 | |
1175 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { | |
1176 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; | |
1177 } else { | |
1178 conf->upstream.max_temp_file_size = | |
1179 conf->upstream.max_temp_file_size_conf; | |
1180 } | |
1181 | |
1182 if (conf->upstream.max_temp_file_size != 0 | |
1183 && conf->upstream.max_temp_file_size < size) { | |
1184 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1185 "\"scgi_max_temp_file_size\" must be equal to zero to disable " | |
1186 "the temporary files usage or must be equal or bigger than " | |
1187 "maximum of the value of \"scgi_buffer_size\" and " | |
1188 "one of the \"scgi_buffers\""); | |
1189 | |
1190 return NGX_CONF_ERROR; | |
1191 } | |
1192 | |
1193 | |
1194 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers, | |
1195 prev->upstream.ignore_headers, | |
1196 NGX_CONF_BITMASK_SET); | |
1197 | |
1198 | |
1199 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, | |
1200 prev->upstream.next_upstream, | |
1201 (NGX_CONF_BITMASK_SET | |
1202 |NGX_HTTP_UPSTREAM_FT_ERROR | |
1203 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
1204 | |
1205 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { | |
1206 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
1207 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1208 } | |
1209 | |
1210 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path, | |
1211 prev->upstream.temp_path, | |
1212 &ngx_http_scgi_temp_path) | |
1213 != NGX_OK) | |
1214 { | |
1215 return NGX_CONF_ERROR; | |
1216 } | |
1217 | |
1218 #if (NGX_HTTP_CACHE) | |
1219 | |
1220 ngx_conf_merge_ptr_value(conf->upstream.cache, | |
1221 prev->upstream.cache, NULL); | |
1222 | |
1223 if (conf->upstream.cache && conf->upstream.cache->data == NULL) { | |
1224 ngx_shm_zone_t *shm_zone; | |
1225 | |
1226 shm_zone = conf->upstream.cache; | |
1227 | |
1228 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1229 "\"scgi_cache\" zone \"%V\" is unknown", | |
1230 &shm_zone->shm.name); | |
1231 | |
1232 return NGX_CONF_ERROR; | |
1233 } | |
1234 | |
1235 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses, | |
1236 prev->upstream.cache_min_uses, 1); | |
1237 | |
1238 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale, | |
1239 prev->upstream.cache_use_stale, | |
1240 (NGX_CONF_BITMASK_SET | |
1241 |NGX_HTTP_UPSTREAM_FT_OFF)); | |
1242 | |
1243 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) { | |
1244 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET | |
1245 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1246 } | |
1247 | |
1248 if (conf->upstream.cache_methods == 0) { | |
1249 conf->upstream.cache_methods = prev->upstream.cache_methods; | |
1250 } | |
1251 | |
1252 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD; | |
1253 | |
1254 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass, | |
1255 prev->upstream.cache_bypass, NULL); | |
1256 | |
1257 ngx_conf_merge_ptr_value(conf->upstream.no_cache, | |
1258 prev->upstream.no_cache, NULL); | |
1259 | |
1260 ngx_conf_merge_ptr_value(conf->upstream.cache_valid, | |
1261 prev->upstream.cache_valid, NULL); | |
1262 | |
1263 if (conf->cache_key.value.data == NULL) { | |
1264 conf->cache_key = prev->cache_key; | |
1265 } | |
1266 | |
1267 #endif | |
1268 | |
1269 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
1270 prev->upstream.pass_request_headers, 1); | |
1271 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
1272 prev->upstream.pass_request_body, 1); | |
1273 | |
1274 ngx_conf_merge_value(conf->upstream.intercept_errors, | |
1275 prev->upstream.intercept_errors, 0); | |
1276 | |
1277 hash.max_size = 512; | |
1278 hash.bucket_size = ngx_align(64, ngx_cacheline_size); | |
1279 hash.name = "scgi_hide_headers_hash"; | |
1280 | |
1281 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream, | |
1282 &prev->upstream, ngx_http_scgi_hide_headers, &hash) | |
1283 != NGX_OK) | |
1284 { | |
1285 return NGX_CONF_ERROR; | |
1286 } | |
1287 | |
1288 if (conf->upstream.upstream == NULL) { | |
1289 conf->upstream.upstream = prev->upstream.upstream; | |
1290 } | |
1291 | |
1292 if (conf->scgi_lengths == NULL) { | |
1293 conf->scgi_lengths = prev->scgi_lengths; | |
1294 conf->scgi_values = prev->scgi_values; | |
1295 } | |
1296 | |
1297 if (conf->upstream.upstream || conf->scgi_lengths) { | |
1298 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
1299 if (clcf->handler == NULL && clcf->lmt_excpt) { | |
1300 clcf->handler = ngx_http_scgi_handler; | |
1301 } | |
1302 } | |
1303 | |
1304 if (ngx_http_scgi_merge_params(cf, conf, prev) != NGX_OK) { | |
1305 return NGX_CONF_ERROR; | |
1306 } | |
1307 | |
1308 return NGX_CONF_OK; | |
1309 } | |
1310 | |
1311 | |
1312 static ngx_int_t | |
1313 ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf, | |
1314 ngx_http_scgi_loc_conf_t *prev) | |
1315 { | |
1062 u_char *p; | 1316 u_char *p; |
1063 size_t size; | 1317 size_t size; |
1064 uintptr_t *code; | 1318 uintptr_t *code; |
1065 ngx_uint_t i; | 1319 ngx_uint_t i; |
1066 ngx_array_t headers_names; | 1320 ngx_array_t headers_names; |
1067 ngx_keyval_t *src; | 1321 ngx_keyval_t *src; |
1068 ngx_hash_key_t *hk; | 1322 ngx_hash_key_t *hk; |
1069 ngx_hash_init_t hash; | 1323 ngx_hash_init_t hash; |
1070 ngx_http_core_loc_conf_t *clcf; | |
1071 ngx_http_script_compile_t sc; | 1324 ngx_http_script_compile_t sc; |
1072 ngx_http_script_copy_code_t *copy; | 1325 ngx_http_script_copy_code_t *copy; |
1073 | |
1074 if (conf->upstream.store != 0) { | |
1075 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0); | |
1076 | |
1077 if (conf->upstream.store_lengths == NULL) { | |
1078 conf->upstream.store_lengths = prev->upstream.store_lengths; | |
1079 conf->upstream.store_values = prev->upstream.store_values; | |
1080 } | |
1081 } | |
1082 | |
1083 ngx_conf_merge_uint_value(conf->upstream.store_access, | |
1084 prev->upstream.store_access, 0600); | |
1085 | |
1086 ngx_conf_merge_value(conf->upstream.buffering, | |
1087 prev->upstream.buffering, 1); | |
1088 | |
1089 ngx_conf_merge_value(conf->upstream.ignore_client_abort, | |
1090 prev->upstream.ignore_client_abort, 0); | |
1091 | |
1092 ngx_conf_merge_msec_value(conf->upstream.connect_timeout, | |
1093 prev->upstream.connect_timeout, 60000); | |
1094 | |
1095 ngx_conf_merge_msec_value(conf->upstream.send_timeout, | |
1096 prev->upstream.send_timeout, 60000); | |
1097 | |
1098 ngx_conf_merge_msec_value(conf->upstream.read_timeout, | |
1099 prev->upstream.read_timeout, 60000); | |
1100 | |
1101 ngx_conf_merge_size_value(conf->upstream.send_lowat, | |
1102 prev->upstream.send_lowat, 0); | |
1103 | |
1104 ngx_conf_merge_size_value(conf->upstream.buffer_size, | |
1105 prev->upstream.buffer_size, | |
1106 (size_t) ngx_pagesize); | |
1107 | |
1108 | |
1109 ngx_conf_merge_bufs_value(conf->upstream.bufs, prev->upstream.bufs, | |
1110 8, ngx_pagesize); | |
1111 | |
1112 if (conf->upstream.bufs.num < 2) { | |
1113 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1114 "there must be at least 2 \"scgi_buffers\""); | |
1115 return NGX_CONF_ERROR; | |
1116 } | |
1117 | |
1118 | |
1119 size = conf->upstream.buffer_size; | |
1120 if (size < conf->upstream.bufs.size) { | |
1121 size = conf->upstream.bufs.size; | |
1122 } | |
1123 | |
1124 | |
1125 ngx_conf_merge_size_value(conf->upstream.busy_buffers_size_conf, | |
1126 prev->upstream.busy_buffers_size_conf, | |
1127 NGX_CONF_UNSET_SIZE); | |
1128 | |
1129 if (conf->upstream.busy_buffers_size_conf == NGX_CONF_UNSET_SIZE) { | |
1130 conf->upstream.busy_buffers_size = 2 * size; | |
1131 } else { | |
1132 conf->upstream.busy_buffers_size = | |
1133 conf->upstream.busy_buffers_size_conf; | |
1134 } | |
1135 | |
1136 if (conf->upstream.busy_buffers_size < size) { | |
1137 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1138 "\"scgi_busy_buffers_size\" must be equal or bigger " | |
1139 "than maximum of the value of \"scgi_buffer_size\" and " | |
1140 "one of the \"scgi_buffers\""); | |
1141 | |
1142 return NGX_CONF_ERROR; | |
1143 } | |
1144 | |
1145 if (conf->upstream.busy_buffers_size | |
1146 > (conf->upstream.bufs.num - 1) * conf->upstream.bufs.size) | |
1147 { | |
1148 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1149 "\"scgi_busy_buffers_size\" must be less than " | |
1150 "the size of all \"scgi_buffers\" minus one buffer"); | |
1151 | |
1152 return NGX_CONF_ERROR; | |
1153 } | |
1154 | |
1155 | |
1156 ngx_conf_merge_size_value(conf->upstream.temp_file_write_size_conf, | |
1157 prev->upstream.temp_file_write_size_conf, | |
1158 NGX_CONF_UNSET_SIZE); | |
1159 | |
1160 if (conf->upstream.temp_file_write_size_conf == NGX_CONF_UNSET_SIZE) { | |
1161 conf->upstream.temp_file_write_size = 2 * size; | |
1162 } else { | |
1163 conf->upstream.temp_file_write_size = | |
1164 conf->upstream.temp_file_write_size_conf; | |
1165 } | |
1166 | |
1167 if (conf->upstream.temp_file_write_size < size) { | |
1168 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1169 "\"scgi_temp_file_write_size\" must be equal or bigger than " | |
1170 "maximum of the value of \"scgi_buffer_size\" and " | |
1171 "one of the \"scgi_buffers\""); | |
1172 | |
1173 return NGX_CONF_ERROR; | |
1174 } | |
1175 | |
1176 | |
1177 ngx_conf_merge_size_value(conf->upstream.max_temp_file_size_conf, | |
1178 prev->upstream.max_temp_file_size_conf, | |
1179 NGX_CONF_UNSET_SIZE); | |
1180 | |
1181 if (conf->upstream.max_temp_file_size_conf == NGX_CONF_UNSET_SIZE) { | |
1182 conf->upstream.max_temp_file_size = 1024 * 1024 * 1024; | |
1183 } else { | |
1184 conf->upstream.max_temp_file_size = | |
1185 conf->upstream.max_temp_file_size_conf; | |
1186 } | |
1187 | |
1188 if (conf->upstream.max_temp_file_size != 0 | |
1189 && conf->upstream.max_temp_file_size < size) { | |
1190 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1191 "\"scgi_max_temp_file_size\" must be equal to zero to disable " | |
1192 "the temporary files usage or must be equal or bigger than " | |
1193 "maximum of the value of \"scgi_buffer_size\" and " | |
1194 "one of the \"scgi_buffers\""); | |
1195 | |
1196 return NGX_CONF_ERROR; | |
1197 } | |
1198 | |
1199 | |
1200 ngx_conf_merge_bitmask_value(conf->upstream.ignore_headers, | |
1201 prev->upstream.ignore_headers, | |
1202 NGX_CONF_BITMASK_SET); | |
1203 | |
1204 | |
1205 ngx_conf_merge_bitmask_value(conf->upstream.next_upstream, | |
1206 prev->upstream.next_upstream, | |
1207 (NGX_CONF_BITMASK_SET | |
1208 |NGX_HTTP_UPSTREAM_FT_ERROR | |
1209 |NGX_HTTP_UPSTREAM_FT_TIMEOUT)); | |
1210 | |
1211 if (conf->upstream.next_upstream & NGX_HTTP_UPSTREAM_FT_OFF) { | |
1212 conf->upstream.next_upstream = NGX_CONF_BITMASK_SET | |
1213 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1214 } | |
1215 | |
1216 if (ngx_conf_merge_path_value(cf, &conf->upstream.temp_path, | |
1217 prev->upstream.temp_path, | |
1218 &ngx_http_scgi_temp_path) | |
1219 != NGX_OK) | |
1220 { | |
1221 return NGX_CONF_ERROR; | |
1222 } | |
1223 | |
1224 #if (NGX_HTTP_CACHE) | |
1225 | |
1226 ngx_conf_merge_ptr_value(conf->upstream.cache, | |
1227 prev->upstream.cache, NULL); | |
1228 | |
1229 if (conf->upstream.cache && conf->upstream.cache->data == NULL) { | |
1230 ngx_shm_zone_t *shm_zone; | |
1231 | |
1232 shm_zone = conf->upstream.cache; | |
1233 | |
1234 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, | |
1235 "\"scgi_cache\" zone \"%V\" is unknown", | |
1236 &shm_zone->shm.name); | |
1237 | |
1238 return NGX_CONF_ERROR; | |
1239 } | |
1240 | |
1241 ngx_conf_merge_uint_value(conf->upstream.cache_min_uses, | |
1242 prev->upstream.cache_min_uses, 1); | |
1243 | |
1244 ngx_conf_merge_bitmask_value(conf->upstream.cache_use_stale, | |
1245 prev->upstream.cache_use_stale, | |
1246 (NGX_CONF_BITMASK_SET | |
1247 |NGX_HTTP_UPSTREAM_FT_OFF)); | |
1248 | |
1249 if (conf->upstream.cache_use_stale & NGX_HTTP_UPSTREAM_FT_OFF) { | |
1250 conf->upstream.cache_use_stale = NGX_CONF_BITMASK_SET | |
1251 |NGX_HTTP_UPSTREAM_FT_OFF; | |
1252 } | |
1253 | |
1254 if (conf->upstream.cache_methods == 0) { | |
1255 conf->upstream.cache_methods = prev->upstream.cache_methods; | |
1256 } | |
1257 | |
1258 conf->upstream.cache_methods |= NGX_HTTP_GET|NGX_HTTP_HEAD; | |
1259 | |
1260 ngx_conf_merge_ptr_value(conf->upstream.cache_bypass, | |
1261 prev->upstream.cache_bypass, NULL); | |
1262 | |
1263 ngx_conf_merge_ptr_value(conf->upstream.no_cache, | |
1264 prev->upstream.no_cache, NULL); | |
1265 | |
1266 ngx_conf_merge_ptr_value(conf->upstream.cache_valid, | |
1267 prev->upstream.cache_valid, NULL); | |
1268 | |
1269 if (conf->cache_key.value.data == NULL) { | |
1270 conf->cache_key = prev->cache_key; | |
1271 } | |
1272 | |
1273 #endif | |
1274 | |
1275 ngx_conf_merge_value(conf->upstream.pass_request_headers, | |
1276 prev->upstream.pass_request_headers, 1); | |
1277 ngx_conf_merge_value(conf->upstream.pass_request_body, | |
1278 prev->upstream.pass_request_body, 1); | |
1279 | |
1280 ngx_conf_merge_value(conf->upstream.intercept_errors, | |
1281 prev->upstream.intercept_errors, 0); | |
1282 | |
1283 hash.max_size = 512; | |
1284 hash.bucket_size = ngx_align(64, ngx_cacheline_size); | |
1285 hash.name = "scgi_hide_headers_hash"; | |
1286 | |
1287 if (ngx_http_upstream_hide_headers_hash(cf, &conf->upstream, | |
1288 &prev->upstream, ngx_http_scgi_hide_headers, &hash) | |
1289 != NGX_OK) | |
1290 { | |
1291 return NGX_CONF_ERROR; | |
1292 } | |
1293 | |
1294 if (conf->upstream.upstream == NULL) { | |
1295 conf->upstream.upstream = prev->upstream.upstream; | |
1296 } | |
1297 | |
1298 if (conf->scgi_lengths == NULL) { | |
1299 conf->scgi_lengths = prev->scgi_lengths; | |
1300 conf->scgi_values = prev->scgi_values; | |
1301 } | |
1302 | |
1303 if (conf->upstream.upstream || conf->scgi_lengths) { | |
1304 clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module); | |
1305 if (clcf->handler == NULL && clcf->lmt_excpt) { | |
1306 clcf->handler = ngx_http_scgi_handler; | |
1307 } | |
1308 } | |
1309 | 1326 |
1310 if (conf->params_source == NULL) { | 1327 if (conf->params_source == NULL) { |
1311 conf->flushes = prev->flushes; | 1328 conf->flushes = prev->flushes; |
1312 conf->params_len = prev->params_len; | 1329 conf->params_len = prev->params_len; |
1313 conf->params = prev->params; | 1330 conf->params = prev->params; |
1319 if (conf->params_source == NULL) { | 1336 if (conf->params_source == NULL) { |
1320 | 1337 |
1321 if ((conf->upstream.cache == NULL) | 1338 if ((conf->upstream.cache == NULL) |
1322 == (prev->upstream.cache == NULL)) | 1339 == (prev->upstream.cache == NULL)) |
1323 { | 1340 { |
1324 return NGX_CONF_OK; | 1341 return NGX_OK; |
1325 } | 1342 } |
1326 | 1343 |
1327 /* 6 is a number of ngx_http_scgi_cache_headers entries */ | 1344 /* 6 is a number of ngx_http_scgi_cache_headers entries */ |
1328 conf->params_source = ngx_array_create(cf->pool, 6, | 1345 conf->params_source = ngx_array_create(cf->pool, 6, |
1329 sizeof(ngx_keyval_t)); | 1346 sizeof(ngx_keyval_t)); |
1330 if (conf->params_source == NULL) { | 1347 if (conf->params_source == NULL) { |
1331 return NGX_CONF_ERROR; | 1348 return NGX_ERROR; |
1332 } | 1349 } |
1333 } | 1350 } |
1334 #else | 1351 #else |
1335 | 1352 |
1336 if (conf->params_source == NULL) { | 1353 if (conf->params_source == NULL) { |
1337 return NGX_CONF_OK; | 1354 return NGX_OK; |
1338 } | 1355 } |
1339 | 1356 |
1340 #endif | 1357 #endif |
1341 } | 1358 } |
1342 | 1359 |
1343 conf->params_len = ngx_array_create(cf->pool, 64, 1); | 1360 conf->params_len = ngx_array_create(cf->pool, 64, 1); |
1344 if (conf->params_len == NULL) { | 1361 if (conf->params_len == NULL) { |
1345 return NGX_CONF_ERROR; | 1362 return NGX_ERROR; |
1346 } | 1363 } |
1347 | 1364 |
1348 conf->params = ngx_array_create(cf->pool, 512, 1); | 1365 conf->params = ngx_array_create(cf->pool, 512, 1); |
1349 if (conf->params == NULL) { | 1366 if (conf->params == NULL) { |
1350 return NGX_CONF_ERROR; | 1367 return NGX_ERROR; |
1351 } | 1368 } |
1352 | 1369 |
1353 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | 1370 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) |
1354 != NGX_OK) | 1371 != NGX_OK) |
1355 { | 1372 { |
1356 return NGX_CONF_ERROR; | 1373 return NGX_ERROR; |
1357 } | 1374 } |
1358 | 1375 |
1359 src = conf->params_source->elts; | 1376 src = conf->params_source->elts; |
1360 | 1377 |
1361 #if (NGX_HTTP_CACHE) | 1378 #if (NGX_HTTP_CACHE) |
1371 } | 1388 } |
1372 } | 1389 } |
1373 | 1390 |
1374 s = ngx_array_push(conf->params_source); | 1391 s = ngx_array_push(conf->params_source); |
1375 if (s == NULL) { | 1392 if (s == NULL) { |
1376 return NGX_CONF_ERROR; | 1393 return NGX_ERROR; |
1377 } | 1394 } |
1378 | 1395 |
1379 *s = *h; | 1396 *s = *h; |
1380 | 1397 |
1381 src = conf->params_source->elts; | 1398 src = conf->params_source->elts; |
1393 if (src[i].key.len > sizeof("HTTP_") - 1 | 1410 if (src[i].key.len > sizeof("HTTP_") - 1 |
1394 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) | 1411 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) |
1395 { | 1412 { |
1396 hk = ngx_array_push(&headers_names); | 1413 hk = ngx_array_push(&headers_names); |
1397 if (hk == NULL) { | 1414 if (hk == NULL) { |
1398 return NGX_CONF_ERROR; | 1415 return NGX_ERROR; |
1399 } | 1416 } |
1400 | 1417 |
1401 hk->key.len = src[i].key.len - 5; | 1418 hk->key.len = src[i].key.len - 5; |
1402 hk->key.data = src[i].key.data + 5; | 1419 hk->key.data = src[i].key.data + 5; |
1403 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len); | 1420 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len); |
1409 } | 1426 } |
1410 | 1427 |
1411 copy = ngx_array_push_n(conf->params_len, | 1428 copy = ngx_array_push_n(conf->params_len, |
1412 sizeof(ngx_http_script_copy_code_t)); | 1429 sizeof(ngx_http_script_copy_code_t)); |
1413 if (copy == NULL) { | 1430 if (copy == NULL) { |
1414 return NGX_CONF_ERROR; | 1431 return NGX_ERROR; |
1415 } | 1432 } |
1416 | 1433 |
1417 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | 1434 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; |
1418 copy->len = src[i].key.len + 1; | 1435 copy->len = src[i].key.len + 1; |
1419 | 1436 |
1422 + src[i].key.len + 1 + sizeof(uintptr_t) - 1) | 1439 + src[i].key.len + 1 + sizeof(uintptr_t) - 1) |
1423 & ~(sizeof(uintptr_t) - 1); | 1440 & ~(sizeof(uintptr_t) - 1); |
1424 | 1441 |
1425 copy = ngx_array_push_n(conf->params, size); | 1442 copy = ngx_array_push_n(conf->params, size); |
1426 if (copy == NULL) { | 1443 if (copy == NULL) { |
1427 return NGX_CONF_ERROR; | 1444 return NGX_ERROR; |
1428 } | 1445 } |
1429 | 1446 |
1430 copy->code = ngx_http_script_copy_code; | 1447 copy->code = ngx_http_script_copy_code; |
1431 copy->len = src[i].key.len + 1; | 1448 copy->len = src[i].key.len + 1; |
1432 | 1449 |
1441 sc.flushes = &conf->flushes; | 1458 sc.flushes = &conf->flushes; |
1442 sc.lengths = &conf->params_len; | 1459 sc.lengths = &conf->params_len; |
1443 sc.values = &conf->params; | 1460 sc.values = &conf->params; |
1444 | 1461 |
1445 if (ngx_http_script_compile(&sc) != NGX_OK) { | 1462 if (ngx_http_script_compile(&sc) != NGX_OK) { |
1446 return NGX_CONF_ERROR; | 1463 return NGX_ERROR; |
1447 } | 1464 } |
1448 | 1465 |
1449 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 1466 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); |
1450 if (code == NULL) { | 1467 if (code == NULL) { |
1451 return NGX_CONF_ERROR; | 1468 return NGX_ERROR; |
1452 } | 1469 } |
1453 | 1470 |
1454 *code = (uintptr_t) NULL; | 1471 *code = (uintptr_t) NULL; |
1455 | 1472 |
1456 | 1473 |
1457 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | 1474 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); |
1458 if (code == NULL) { | 1475 if (code == NULL) { |
1459 return NGX_CONF_ERROR; | 1476 return NGX_ERROR; |
1460 } | 1477 } |
1461 | 1478 |
1462 *code = (uintptr_t) NULL; | 1479 *code = (uintptr_t) NULL; |
1463 } | 1480 } |
1464 | 1481 |
1465 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 1482 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); |
1466 if (code == NULL) { | 1483 if (code == NULL) { |
1467 return NGX_CONF_ERROR; | 1484 return NGX_ERROR; |
1468 } | 1485 } |
1469 | 1486 |
1470 *code = (uintptr_t) NULL; | 1487 *code = (uintptr_t) NULL; |
1471 | 1488 |
1472 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | 1489 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); |
1473 if (code == NULL) { | 1490 if (code == NULL) { |
1474 return NGX_CONF_ERROR; | 1491 return NGX_ERROR; |
1475 } | 1492 } |
1476 | 1493 |
1477 *code = (uintptr_t) NULL; | 1494 *code = (uintptr_t) NULL; |
1478 | 1495 |
1479 conf->header_params = headers_names.nelts; | 1496 conf->header_params = headers_names.nelts; |
1484 hash.bucket_size = 64; | 1501 hash.bucket_size = 64; |
1485 hash.name = "scgi_params_hash"; | 1502 hash.name = "scgi_params_hash"; |
1486 hash.pool = cf->pool; | 1503 hash.pool = cf->pool; |
1487 hash.temp_pool = NULL; | 1504 hash.temp_pool = NULL; |
1488 | 1505 |
1489 if (ngx_hash_init(&hash, headers_names.elts, headers_names.nelts) != NGX_OK) | 1506 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts); |
1490 { | |
1491 return NGX_CONF_ERROR; | |
1492 } | |
1493 | |
1494 return NGX_CONF_OK; | |
1495 } | 1507 } |
1496 | 1508 |
1497 | 1509 |
1498 static char * | 1510 static char * |
1499 ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) | 1511 ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) |