Browse Source

[mod_redirect,mod_rewrite] short-circuit earlier

short-circuit earlier if there are no rules to be matched
personal/stbuehler/fix-fdevent
Glenn Strauss 4 years ago
parent
commit
1c68589c67
  1. 1
      src/mod_redirect.c
  2. 18
      src/mod_rewrite.c

1
src/mod_redirect.c

@ -151,6 +151,7 @@ URIHANDLER_FUNC(mod_redirect_uri_handler) {
handler_t rc;
mod_redirect_patch_connection(srv, con, p);
if (!p->conf.redirect->used) return HANDLER_GO_ON;
ctx.cache = p->conf.context
? &con->cond_cache[p->conf.context->context_ndx]
: NULL;

18
src/mod_rewrite.c

@ -259,6 +259,7 @@ static handler_t process_rewrite_rules(server *srv, connection *con, plugin_data
hctx = con->plugin_ctx[p->id];
}
if (ctx.m < repeat_idx) hctx->state = REWRITE_STATE_FINISHED;
buffer_reset(con->physical.path);
rc = HANDLER_COMEBACK;
}
else if (HANDLER_ERROR == rc) {
@ -271,15 +272,13 @@ static handler_t process_rewrite_rules(server *srv, connection *con, plugin_data
URIHANDLER_FUNC(mod_rewrite_physical) {
plugin_data *p = p_d;
handler_t r;
stat_cache_entry *sce;
if (con->mode != DIRECT) return HANDLER_GO_ON;
mod_rewrite_patch_connection(srv, con, p);
p->conf.context = p->conf.context_NF;
if (!p->conf.rewrite_NF) return HANDLER_GO_ON;
if (!p->conf.rewrite_NF->used) return HANDLER_GO_ON;
/* skip if physical.path is a regular file */
sce = NULL;
@ -287,23 +286,14 @@ URIHANDLER_FUNC(mod_rewrite_physical) {
if (S_ISREG(sce->st.st_mode)) return HANDLER_GO_ON;
}
switch(r = process_rewrite_rules(srv, con, p, p->conf.rewrite_NF, p->conf.rewrite_NF_repeat_idx)) {
case HANDLER_COMEBACK:
buffer_reset(con->physical.path);
/* fall through */
default:
return r;
}
return HANDLER_GO_ON;
return process_rewrite_rules(srv, con, p, p->conf.rewrite_NF, p->conf.rewrite_NF_repeat_idx);
}
URIHANDLER_FUNC(mod_rewrite_uri_handler) {
plugin_data *p = p_d;
mod_rewrite_patch_connection(srv, con, p);
if (!p->conf.rewrite) return HANDLER_GO_ON;
if (!p->conf.rewrite->used) return HANDLER_GO_ON;
return process_rewrite_rules(srv, con, p, p->conf.rewrite, p->conf.rewrite_repeat_idx);
}

Loading…
Cancel
Save