* Send uwsgi header block */
| 146 | * Send uwsgi header block |
| 147 | */ |
| 148 | static int uwsgi_send_headers(request_rec *r, proxy_conn_rec * conn) |
| 149 | { |
| 150 | char *buf, *ptr; |
| 151 | |
| 152 | const apr_array_header_t *env_table; |
| 153 | const apr_table_entry_t *env; |
| 154 | |
| 155 | int j; |
| 156 | |
| 157 | apr_size_t headerlen = 4; |
| 158 | apr_size_t pktsize, keylen, vallen; |
| 159 | const char *script_name; |
| 160 | const char *path_info; |
| 161 | const char *auth; |
| 162 | |
| 163 | ap_add_common_vars(r); |
| 164 | ap_add_cgi_vars(r); |
| 165 | |
| 166 | /* |
| 167 | this is not a security problem (in Linux) as uWSGI destroy the env memory area readable in /proc |
| 168 | and generally if you host untrusted apps in your server and allows them to read others uid /proc/<pid> |
| 169 | files you have higher problems... |
| 170 | */ |
| 171 | auth = apr_table_get(r->headers_in, "Authorization"); |
| 172 | if (auth) { |
| 173 | apr_table_setn(r->subprocess_env, "HTTP_AUTHORIZATION", auth); |
| 174 | } |
| 175 | |
| 176 | script_name = apr_table_get(r->subprocess_env, "SCRIPT_NAME"); |
| 177 | path_info = apr_table_get(r->subprocess_env, "PATH_INFO"); |
| 178 | |
| 179 | if (script_name && path_info) { |
| 180 | if (strcmp(path_info, "/")) { |
| 181 | apr_table_set(r->subprocess_env, "SCRIPT_NAME", |
| 182 | apr_pstrndup(r->pool, script_name, |
| 183 | strlen(script_name) - |
| 184 | strlen(path_info))); |
| 185 | } |
| 186 | else { |
| 187 | if (!strcmp(script_name, "/")) { |
| 188 | apr_table_setn(r->subprocess_env, "SCRIPT_NAME", ""); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | env_table = apr_table_elts(r->subprocess_env); |
| 194 | env = (apr_table_entry_t *) env_table->elts; |
| 195 | |
| 196 | for (j = 0; j < env_table->nelts; ++j) { |
| 197 | headerlen += 2 + strlen(env[j].key) + 2 + (env[j].val ? strlen(env[j].val) : 0); |
| 198 | } |
| 199 | |
| 200 | pktsize = headerlen - 4; |
| 201 | if (pktsize > APR_UINT16_MAX) { |
| 202 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(10259) |
| 203 | "can't send headers to %s:%u: packet size too " |
| 204 | "large (%" APR_SIZE_T_FMT ")", |
| 205 | conn->hostname, conn->port, pktsize); |
no test coverage detected