There are two options regarding what the "name" of a server is. The * "canonical" name as defined by ServerName and Port, or the "client's * name" as supplied by a possible Host: header or full URI. * * The DNS option to UseCanonicalName causes this routine to do a * reverse lookup on the local IP address of the connection and use * that for the ServerName. This makes its value more reliabl
| 1143 | * -- fanf 1998-10-03 |
| 1144 | */ |
| 1145 | AP_DECLARE(const char *) ap_get_server_name(request_rec *r) |
| 1146 | { |
| 1147 | conn_rec *conn = r->connection; |
| 1148 | core_dir_config *d; |
| 1149 | const char *retval; |
| 1150 | |
| 1151 | d = (core_dir_config *)ap_get_core_module_config(r->per_dir_config); |
| 1152 | |
| 1153 | switch (d->use_canonical_name) { |
| 1154 | case USE_CANONICAL_NAME_ON: |
| 1155 | retval = r->server->server_hostname; |
| 1156 | break; |
| 1157 | case USE_CANONICAL_NAME_DNS: |
| 1158 | if (conn->local_host == NULL) { |
| 1159 | if (apr_getnameinfo(&conn->local_host, |
| 1160 | conn->local_addr, 0) != APR_SUCCESS) |
| 1161 | conn->local_host = apr_pstrdup(conn->pool, |
| 1162 | r->server->server_hostname); |
| 1163 | else { |
| 1164 | ap_str_tolower(conn->local_host); |
| 1165 | } |
| 1166 | } |
| 1167 | retval = conn->local_host; |
| 1168 | break; |
| 1169 | case USE_CANONICAL_NAME_OFF: |
| 1170 | case USE_CANONICAL_NAME_UNSET: |
| 1171 | retval = r->hostname ? r->hostname : r->server->server_hostname; |
| 1172 | break; |
| 1173 | default: |
| 1174 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00109) |
| 1175 | "ap_get_server_name: Invalid UCN Option somehow"); |
| 1176 | retval = "localhost"; |
| 1177 | break; |
| 1178 | } |
| 1179 | return retval; |
| 1180 | } |
| 1181 | |
| 1182 | /* |
| 1183 | * Get the current server name from the request for the purposes |
no test coverage detected