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

Function ap_proxy_trans_match

modules/proxy/mod_proxy.c:825–977  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

823}
824
825PROXY_DECLARE(int) ap_proxy_trans_match(request_rec *r, struct proxy_alias *ent,
826 proxy_dir_conf *dconf)
827{
828 int len;
829 const char *fake;
830 const char *real;
831 ap_regmatch_t regm[AP_MAX_REG_MATCH];
832 ap_regmatch_t reg1[AP_MAX_REG_MATCH];
833 char *found = NULL;
834 int mismatch = 0;
835 unsigned int nocanon = ent->flags & PROXYPASS_NOCANON;
836 const char *use_uri = nocanon ? r->unparsed_uri : r->uri;
837 const char *servlet_uri = NULL;
838
839 if (dconf && (dconf->interpolate_env == 1) && (ent->flags & PROXYPASS_INTERPOLATE)) {
840 fake = ap_proxy_interpolate(r, ent->fake);
841 real = ap_proxy_interpolate(r, ent->real);
842 }
843 else {
844 fake = ent->fake;
845 real = ent->real;
846 }
847
848 ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, APLOGNO(03461)
849 "attempting to match URI path '%s' against %s '%s' for "
850 "proxying", r->uri, (ent->regex ? "pattern" : "prefix"),
851 fake);
852
853 if (ent->regex) {
854 if (!ap_regexec(ent->regex, r->uri, AP_MAX_REG_MATCH, regm, 0)) {
855 if ((real[0] == '!') && (real[1] == '\0')) {
856 ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(03462)
857 "proxying is explicitly disabled for URI path "
858 "'%s'; declining", r->uri);
859 return DECLINED;
860 }
861 /* test that we haven't reduced the URI */
862 if (nocanon && ap_regexec(ent->regex, r->unparsed_uri,
863 AP_MAX_REG_MATCH, reg1, 0)) {
864 mismatch = 1;
865 use_uri = r->uri;
866 }
867 found = ap_pregsub(r->pool, real, use_uri, AP_MAX_REG_MATCH,
868 (use_uri == r->uri) ? regm : reg1);
869 if (!found) {
870 ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(01135)
871 "Substitution in regular expression failed. "
872 "Replacement too long?");
873 return HTTP_INTERNAL_SERVER_ERROR;
874 }
875
876 /* Note: The strcmp() below catches cases where there
877 * was no regex substitution. This is so cases like:
878 *
879 * ProxyPassMatch \.gif balancer://foo
880 *
881 * will work "as expected". The upshot is that the 2
882 * directives below act the exact same way (ie: $1 is implied):

Callers 1

proxy_transFunction · 0.85

Calls 5

ap_proxy_interpolateFunction · 0.85
ap_regexecFunction · 0.85
ap_pregsubFunction · 0.85
alias_match_servletFunction · 0.85
alias_matchFunction · 0.85

Tested by

no test coverage detected