From 6fbbe01f84f5c0c357d96d681020a7109bad762b Mon Sep 17 00:00:00 2001 From: "Hongli Lai (Phusion)" Date: Wed, 18 Jul 2012 16:27:08 +0200 Subject: [PATCH] Fixed some mod_rewrite compatibility problems. Fixes issue #563. --- NEWS | 10 ++++++++++ ext/apache2/Hooks.cpp | 28 +++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index cdbf3723d9..268bc237b7 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,13 @@ +Release 3.0.14 +-------------- + + * [Apache] Fixed a long-standing mod_rewrite-related problem. + Some mod_rewrite rules would not work, but it depends on the exact + mod_rewrite configuration so it would work for some people but not + for others. Issue #563. Thanks a lot to cedricmaion for providing + information on the nature of the bug. + + Release 3.0.13 -------------- diff --git a/ext/apache2/Hooks.cpp b/ext/apache2/Hooks.cpp index 02f636ac54..2f485576a9 100644 --- a/ext/apache2/Hooks.cpp +++ b/ext/apache2/Hooks.cpp @@ -159,6 +159,7 @@ class Hooks { char *filenameBeforeModRewrite; apr_filetype_e oldFileType; const char *handlerBeforeModAutoIndex; + bool enabled; RequestNote(const DirectoryMapper &m, DirConfig *c) : mapper(m), @@ -169,6 +170,7 @@ class Hooks { filenameBeforeModRewrite = NULL; oldFileType = APR_NOFILE; handlerBeforeModAutoIndex = NULL; + enabled = true; } ~RequestNote() { @@ -239,9 +241,25 @@ class Hooks { * The existance of a request note means that the handler should be run. */ inline RequestNote *getRequestNote(request_rec *r) { - void *note = 0; - apr_pool_userdata_get(¬e, "Phusion Passenger", r->pool); - return (RequestNote *) note; + void *pointer = 0; + apr_pool_userdata_get(&pointer, "Phusion Passenger", r->pool); + if (pointer != NULL) { + RequestNote *note = (RequestNote *) pointer; + if (OXT_LIKELY(note->enabled)) { + return note; + } else { + return 0; + } + } else { + return 0; + } + } + + void disableRequestNote(request_rec *r) { + RequestNote *note = getRequestNote(r); + if (note != NULL) { + note->enabled = false; + } } /** @@ -418,6 +436,7 @@ class Hooks { try { if (mapper.getBaseURI() == NULL) { // (B) is not true. + disableRequestNote(r); return false; } } catch (const FileSystemException &e) { @@ -441,6 +460,7 @@ class Hooks { RequestNote::cleanup, r->pool); return true; } else { + disableRequestNote(r); return false; } } @@ -451,6 +471,7 @@ class Hooks { FileType fileType = getFileType(filename); if (fileType == FT_REGULAR) { // (C) is true. + disableRequestNote(r); return false; } @@ -511,6 +532,7 @@ class Hooks { * don't let the handler hook run so that Apache can decide how * to display the error. */ + disableRequestNote(r); return false; } }