* strip 'http[s]://ourhost/' from URI */
| 899 | * strip 'http[s]://ourhost/' from URI |
| 900 | */ |
| 901 | static void reduce_uri(request_rec *r) |
| 902 | { |
| 903 | char *cp; |
| 904 | apr_size_t l; |
| 905 | |
| 906 | cp = (char *)ap_http_scheme(r); |
| 907 | l = strlen(cp); |
| 908 | if ( strlen(r->filename) > l+3 |
| 909 | && ap_cstr_casecmpn(r->filename, cp, l) == 0 |
| 910 | && r->filename[l] == ':' |
| 911 | && r->filename[l+1] == '/' |
| 912 | && r->filename[l+2] == '/' ) { |
| 913 | |
| 914 | unsigned short port; |
| 915 | char *portp, *host, *url, *scratch; |
| 916 | |
| 917 | scratch = apr_pstrdup(r->pool, r->filename); /* our scratchpad */ |
| 918 | |
| 919 | /* cut the hostname and port out of the URI */ |
| 920 | cp = host = scratch + l + 3; /* 3 == strlen("://") */ |
| 921 | while (*cp && *cp != '/' && *cp != ':') { |
| 922 | ++cp; |
| 923 | } |
| 924 | |
| 925 | if (*cp == ':') { /* additional port given */ |
| 926 | *cp++ = '\0'; |
| 927 | portp = cp; |
| 928 | while (*cp && *cp != '/') { |
| 929 | ++cp; |
| 930 | } |
| 931 | *cp = '\0'; |
| 932 | |
| 933 | port = atoi(portp); |
| 934 | url = r->filename + (cp - scratch); |
| 935 | if (!*url) { |
| 936 | url = "/"; |
| 937 | } |
| 938 | } |
| 939 | else if (*cp == '/') { /* default port */ |
| 940 | *cp = '\0'; |
| 941 | |
| 942 | port = ap_default_port(r); |
| 943 | url = r->filename + (cp - scratch); |
| 944 | } |
| 945 | else { |
| 946 | port = ap_default_port(r); |
| 947 | url = "/"; |
| 948 | } |
| 949 | |
| 950 | /* now check whether we could reduce it to a local path... */ |
| 951 | if (ap_matches_request_vhost(r, host, port)) { |
| 952 | rewrite_server_conf *conf = |
| 953 | ap_get_module_config(r->server->module_config, &rewrite_module); |
| 954 | rewritelog(r, 3, NULL, "reduce %s -> %s", r->filename, url); |
| 955 | r->filename = apr_pstrdup(r->pool, url); |
| 956 | |
| 957 | /* remember that the uri was reduced */ |
| 958 | if(!(conf->options & OPTION_LEGACY_PREFIX_DOCROOT)) { |
no test coverage detected