MCPcopy Create free account
hub / github.com/apache/httpd / update_server_from_aliases

Function update_server_from_aliases

server/vhost.c:1000–1090  ·  view source on GitHub ↗

* Updates r->server from ServerName/ServerAlias. Per the interaction * of ip and name-based vhosts, it only looks in the best match from the * connection-level ip-based matching. * Returns HTTP_BAD_REQUEST if there was no match. */

Source from the content-addressed store, hash-verified

998 * Returns HTTP_BAD_REQUEST if there was no match.
999 */
1000static int update_server_from_aliases(request_rec *r)
1001{
1002 /*
1003 * Even if the request has a Host: header containing a port we ignore
1004 * that port. We always use the physical port of the socket. There
1005 * are a few reasons for this:
1006 *
1007 * - the default of 80 or 443 for SSL is easier to handle this way
1008 * - there is less of a possibility of a security problem
1009 * - it simplifies the data structure
1010 * - the client may have no idea that a proxy somewhere along the way
1011 * translated the request to another ip:port
1012 * - except for the addresses from the VirtualHost line, none of the other
1013 * names we'll match have ports associated with them
1014 */
1015 const char *host = r->hostname;
1016 apr_port_t port;
1017 server_rec *s;
1018 server_rec *virthost_s;
1019 server_rec *last_s;
1020 name_chain *src;
1021
1022 virthost_s = NULL;
1023 last_s = NULL;
1024
1025 port = r->connection->local_addr->port;
1026
1027 /* Recall that the name_chain is a list of server_addr_recs, some of
1028 * whose ports may not match. Also each server may appear more than
1029 * once in the chain -- specifically, it will appear once for each
1030 * address from its VirtualHost line which matched. We only want to
1031 * do the full ServerName/ServerAlias comparisons once for each
1032 * server, fortunately we know that all the VirtualHost addresses for
1033 * a single server are adjacent to each other.
1034 */
1035
1036 for (src = r->connection->vhost_lookup_data; src; src = src->next) {
1037 server_addr_rec *sar;
1038
1039 /* We only consider addresses on the name_chain which have a matching
1040 * port
1041 */
1042 sar = src->sar;
1043 if (sar->host_port != 0 && port != sar->host_port) {
1044 continue;
1045 }
1046
1047 s = src->server;
1048
1049 /* If we still need to do ServerName and ServerAlias checks for this
1050 * server, do them now.
1051 */
1052 if (s != last_s) {
1053 /* does it match any ServerName or ServerAlias directive? */
1054 if (matches_aliases(s, host)) {
1055 goto found;
1056 }
1057 }

Callers 1

Calls 1

matches_aliasesFunction · 0.85

Tested by

no test coverage detected