* Canonicalise http-like URLs. * scheme is the scheme for the URL * url is the URL starting with the first '/' */
| 79 | * url is the URL starting with the first '/' |
| 80 | */ |
| 81 | static int proxy_http_canon(request_rec *r, char *url) |
| 82 | { |
| 83 | const char *base_url = url; |
| 84 | char *host, *path, sport[7]; |
| 85 | char *search = NULL; |
| 86 | const char *err; |
| 87 | const char *scheme; |
| 88 | apr_port_t port, def_port; |
| 89 | int is_ssl = 0; |
| 90 | |
| 91 | scheme = get_url_scheme((const char **)&url, &is_ssl); |
| 92 | if (!scheme) { |
| 93 | return DECLINED; |
| 94 | } |
| 95 | port = def_port = (is_ssl) ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT; |
| 96 | |
| 97 | ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, |
| 98 | "HTTP: canonicalising URL %s", base_url); |
| 99 | |
| 100 | /* do syntatic check. |
| 101 | * We break the URL into host, port, path, search |
| 102 | */ |
| 103 | err = ap_proxy_canon_netloc(r->pool, &url, NULL, NULL, &host, &port); |
| 104 | if (err) { |
| 105 | ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(01083) |
| 106 | "error parsing URL %s: %s", base_url, err); |
| 107 | return HTTP_BAD_REQUEST; |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * now parse path/search args, according to rfc1738: |
| 112 | * process the path. |
| 113 | * |
| 114 | * In a reverse proxy, our URL has been processed, so canonicalise |
| 115 | * unless proxy-nocanon is set to say it's raw |
| 116 | * In a forward proxy, we have and MUST NOT MANGLE the original. |
| 117 | */ |
| 118 | switch (r->proxyreq) { |
| 119 | default: /* wtf are we doing here? */ |
| 120 | case PROXYREQ_REVERSE: |
| 121 | if (apr_table_get(r->notes, "proxy-nocanon")) { |
| 122 | path = url; /* this is the raw path */ |
| 123 | } |
| 124 | else if (apr_table_get(r->notes, "proxy-noencode")) { |
| 125 | path = url; /* this is the encoded path already */ |
| 126 | search = r->args; |
| 127 | } |
| 128 | else { |
| 129 | core_dir_config *d = ap_get_core_module_config(r->per_dir_config); |
| 130 | int flags = d->allow_encoded_slashes && !d->decode_encoded_slashes ? PROXY_CANONENC_NOENCODEDSLASHENCODING : 0; |
| 131 | |
| 132 | path = ap_proxy_canonenc_ex(r->pool, url, strlen(url), enc_path, |
| 133 | flags, r->proxyreq); |
| 134 | if (!path) { |
| 135 | return HTTP_BAD_REQUEST; |
| 136 | } |
| 137 | search = r->args; |
| 138 | } |
nothing calls this directly
no test coverage detected