Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01078) "serving URL %s", url);
/* Create space for state information */
status = ap_proxy_acquire_connection(FCGI_SCHEME, &backend, worker,
r->server);
if (status != OK) {
if (backend) {
backend->close = 1;
ap_proxy_release_connection(FCGI_SCHEME, backend, r->server);
}
return status;
}
backend->is_ssl = 0;
/* Step One: Determine Who To Connect To */
uri = apr_palloc(p, sizeof(*uri));
status = ap_proxy_determine_connection(p, r, conf, worker, backend,
uri, &url, proxyname, proxyport,
server_portstr,
sizeof(server_portstr));
if (status != OK) {
goto cleanup;
}
/* This scheme handler does not reuse connections by default, to
* avoid tying up a fastcgi that isn't expecting to work on
* parallel requests. But if the user went out of their way to
* type the default value of disablereuse=off, we'll allow it.
*/
backend->close = 1;
if (worker->s->disablereuse_set && !worker->s->disablereuse) {
backend->close = 0;
}
/* Step Two: Make the Connection */
if (ap_proxy_check_connection(FCGI_SCHEME, backend, r->server, 0,
PROXY_CHECK_CONN_EMPTY)
&& ap_proxy_connect_backend(FCGI_SCHEME, backend, worker,
r->server)) {
ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01079)
"failed to make connection to backend: %s",
backend->hostname);
status = HTTP_SERVICE_UNAVAILABLE;
goto cleanup;
}
/* Step Three: Process the Request */
status = fcgi_do_request(p, r, backend, origin, dconf, uri, url,
server_portstr);
cleanup:
ap_proxy_release_connection(FCGI_SCHEME, backend, r->server);
return status;
}
static void *fcgi_create_dconf(apr_pool_t *p, char *path)
{
fcgi_dirconf_t *a;
a = (fcgi_dirconf_t *)apr_pcalloc(p, sizeof(fcgi_dirconf_t));
a->backend_type = BACKEND_DEFAULT_UNKNOWN;
a->env_fixups = apr_array_make(p, 20, sizeof(sei_entry));
return a;
}
static void *fcgi_merge_dconf(apr_pool_t *p, void *basev, void *overridesv)
{
fcgi_dirconf_t *a, *base, *over;
a = (fcgi_dirconf_t *)apr_pcalloc(p, sizeof(fcgi_dirconf_t));
base = (fcgi_dirconf_t *)basev;
over = (fcgi_dirconf_t *)overridesv;
a->backend_type = (over->backend_type != BACKEND_DEFAULT_UNKNOWN)
? over->backend_type
: base->backend_type;
a->env_fixups = apr_array_append(p, base->env_fixups, over->env_fixups);
return a;
}
static const char *cmd_servertype(cmd_parms *cmd, void *in_dconf,
const char *val)
{
fcgi_dirconf_t *dconf = in_dconf;
if (!strcasecmp(val, "GENERIC")) {
dconf->backend_type = BACKEND_GENERIC;
}
else if (!strcasecmp(val, "FPM")) {
dconf->backend_type = BACKEND_FPM;
}
else {
return "ProxyFCGIBackendType requires one of the following arguments: "
"'GENERIC', 'FPM'";
}
return NULL;
}
static const char *cmd_setenv(cmd_parms *cmd, void *in_dconf,
const char *arg1, const char *arg2,
const char *arg3)
{
fcgi_dirconf_t *dconf = in_dconf;
const char *err;
sei_entry *new;
const char *envvar = arg2;
new = apr_array_push(dconf->env_fixups);
new->cond = ap_expr_parse_cmd(cmd, arg1, 0, &err, NULL);
if (err) {
return apr_psprintf(cmd->pool, "Could not parse expression \"%s\": %s",
arg1, err);
}
if (envvar[0] == '!') {
/* Unset mode. */
if (arg3) {
return apr_psprintf(cmd->pool, "Third argument (\"%s\") is not "
"allowed when using ProxyFCGISetEnvIf's unset "
"mode (%s)", arg3, envvar);
}
else if (!envvar[1]) {
/* i.e. someone tried to give us a name of just "!" */
return "ProxyFCGISetEnvIf: \"!\" is not a valid variable name";
}
new->subst = NULL;
}
else {
/* Set mode. */
if (!arg3) {
/* A missing expr-value should be treated as empty. */
arg3 = "";
}
new->subst = ap_expr_parse_cmd(cmd, arg3, AP_EXPR_FLAG_STRING_RESULT, &err, NULL);
if (err) {
return apr_psprintf(cmd->pool, "Could not parse expression \"%s\": %s",
arg3, err);
}
}
new->envname = envvar;
return NULL;
}
static void register_hooks(apr_pool_t *p)
{
proxy_hook_scheme_handler(proxy_fcgi_handler, NULL, NULL, APR_HOOK_FIRST);
proxy_hook_canon_handler(proxy_fcgi_canon, NULL, NULL, APR_HOOK_FIRST);
}
static const command_rec command_table[] = {
AP_INIT_TAKE1("ProxyFCGIBackendType", cmd_servertype, NULL, OR_FILEINFO,
"Specify the type of FastCGI server: 'Generic', 'FPM'"),
AP_INIT_TAKE23("ProxyFCGISetEnvIf", cmd_setenv, NULL, OR_FILEINFO,
"expr-condition env-name expr-value"),
{ NULL }
};
AP_DECLARE_MODULE(proxy_fcgi) = {
STANDARD20_MODULE_STUFF,
fcgi_create_dconf, /* create per-directory config structure */
fcgi_merge_dconf, /* merge per-directory config structures */
NULL, /* create per-server config structure */
NULL, /* merge per-server config structures */
command_table, /* command apr_table_t */
register_hooks /* register hooks */
};