| 1171 | } |
| 1172 | |
| 1173 | AP_DECLARE(int) ap_update_vhost_from_headers_ex(request_rec *r, int require_match) |
| 1174 | { |
| 1175 | core_server_config *conf = ap_get_core_module_config(r->server->module_config); |
| 1176 | const char *host_header = apr_table_get(r->headers_in, "Host"); |
| 1177 | int is_v6literal = 0; |
| 1178 | int have_hostname_from_url = 0; |
| 1179 | int rc = HTTP_OK; |
| 1180 | |
| 1181 | if (r->hostname) { |
| 1182 | /* |
| 1183 | * If there was a host part in the Request-URI, ignore the 'Host' |
| 1184 | * header. |
| 1185 | */ |
| 1186 | have_hostname_from_url = 1; |
| 1187 | is_v6literal = fix_hostname(r, NULL, conf->http_conformance); |
| 1188 | } |
| 1189 | else if (host_header != NULL) { |
| 1190 | is_v6literal = fix_hostname(r, host_header, conf->http_conformance); |
| 1191 | } |
| 1192 | if (!require_match && r->status != HTTP_OK) |
| 1193 | return HTTP_OK; |
| 1194 | |
| 1195 | if (conf->http_conformance != AP_HTTP_CONFORMANCE_UNSAFE) { |
| 1196 | /* |
| 1197 | * If we have both hostname from an absoluteURI and a Host header, |
| 1198 | * we must ignore the Host header (RFC 2616 5.2). |
| 1199 | * To enforce this, we reset the Host header to the value from the |
| 1200 | * request line. |
| 1201 | */ |
| 1202 | if (have_hostname_from_url && host_header != NULL) { |
| 1203 | const char *repl = construct_host_header(r, is_v6literal); |
| 1204 | apr_table_setn(r->headers_in, "Host", repl); |
| 1205 | ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(02417) |
| 1206 | "Replacing host header '%s' with host '%s' given " |
| 1207 | "in the request uri", host_header, repl); |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | /* check if we tucked away a name_chain */ |
| 1212 | if (r->connection->vhost_lookup_data) { |
| 1213 | if (r->hostname) |
| 1214 | rc = update_server_from_aliases(r); |
| 1215 | else |
| 1216 | check_serverpath(r); |
| 1217 | } |
| 1218 | else if (require_match && r->hostname) { |
| 1219 | /* check the base server config */ |
| 1220 | rc = update_server_from_aliases(r); |
| 1221 | } |
| 1222 | |
| 1223 | return rc; |
| 1224 | } |
| 1225 | |
| 1226 | /** |
| 1227 | * For every virtual host on this connection, call func_cb. |
no test coverage detected