0
@@ -76,11 +76,13 @@ private:
0
ApplicationType appType;
0
inline bool shouldAutoDetectRails() {
0
- return config->autoDetect == DirConfig::ENABLED || config->autoDetect == DirConfig::UNSET;
0
+ return config->autoDetectRails == DirConfig::ENABLED ||
0
+ config->autoDetectRails == DirConfig::UNSET;
0
inline bool shouldAutoDetectRack() {
0
- return config->autoDetect == DirConfig::ENABLED || config->autoDetect == DirConfig::UNSET;
0
+ return config->autoDetectRack == DirConfig::ENABLED ||
0
+ config->autoDetectRack == DirConfig::UNSET;
0
@@ -213,12 +215,12 @@ public:
0
@@ -251,6 +253,27 @@ private:
0
return (ServerConfig *) ap_get_module_config(s->module_config, &passenger_module);
0
+ void reportDocumentRootDeterminationError(request_rec *r) {
0
+ ap_set_content_type(r, "text/html; charset=UTF-8");
0
+ ap_rputs("<h1>Passenger error #1</h1>\n", r);
0
+ ap_rputs("Cannot determine the document root for the current request.", r);
0
+ void reportFileSystemError(request_rec *r, const FileSystemException &e) {
0
+ ap_set_content_type(r, "text/html; charset=UTF-8");
0
+ ap_rputs("<h1>Passenger error #2</h1>\n", r);
0
+ ap_rputs("An error occurred while trying to access '", r);
0
+ ap_rputs(ap_escape_html(r->pool, e.filename().c_str()), r);
0
+ ap_rputs(ap_escape_html(r->pool, e.what()), r);
0
+ if (e.code() == EPERM) {
0
+ ap_rputs("Apache doesn't have read permissions to that file. ", r);
0
+ ap_rputs("Please fix the relevant file permissions.", r);
0
* Convert an HTTP header name to a CGI environment name.
0
@@ -527,23 +550,15 @@ public:
0
- if (mapper.getPublicDirectory().empty()) {
0
- ap_set_content_type(r, "text/html; charset=UTF-8");
0
- ap_rputs("<h1>Passenger error #1</h1>\n", r);
0
- ap_rputs("Cannot determine the location of the Rails application's \"public\" directory.", r);
0
- } // TODO: could throw exception...
0
- ap_set_content_type(r, "text/html; charset=UTF-8");
0
- ap_rputs("<h1>Passenger error #2</h1>\n", r);
0
- ap_rputs("Passenger thought that the Rails application's \"public\" directory is \"", r);
0
- ap_rputs(ap_escape_html(r->pool, railsDir.c_str()), r);
0
- ap_rputs("\". But upon further inspection, it doesn't seem to be a valid Rails ", r);
0
- ap_rputs("\"public\" folder. It is possible that Apache doesn't have read ", r);
0
- ap_rputs("permissions to your Rails application's folder. Please check your ", r);
0
- ap_rputs("file permissions.", r);
0
+ if (mapper.getPublicDirectory().empty()) {
0
+ reportDocumentRootDeterminationError(r);
0
+ } catch (const FileSystemException &e) {
0
+ reportFileSystemError(r, e);
0
int httpStatus = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR);
0
if (httpStatus != OK) {
0
@@ -633,81 +648,86 @@ public:
0
mapToStorage(request_rec *r) {
0
DirConfig *config = getDirConfig(r);
0
DirectoryMapper mapper(r, config);
0
- // TODO: this can throw an exception...
0
- if (mapper.getBaseURI() == NULL || fileExists(r->filename)) {
0
- * If the file already exists, serve it directly.
0
- * This is for static assets like .css and .js files.
0
- forwardToRails = false;
0
- } else if (r->method_number == M_GET) {
0
- len = strlen(r->filename);
0
- if (len > 0 && r->filename[len - 1] == '/') {
0
- html_file = apr_pstrcat(r->pool, r->filename, "index.html", NULL);
0
- html_file = apr_pstrcat(r->pool, r->filename, ".html", NULL);
0
- if (fileExists(html_file)) {
0
- /* If a .html version of the URI exists, serve it directly.
0
- * We're essentially accelerating Rails page caching.
0
+ bool forwardToApplication;
0
+ if (mapper.getBaseURI() == NULL || fileExists(r->filename)) {
0
+ * If the file already exists, serve it directly.
0
+ * This is for static assets like .css and .js files.
0
- r->filename = html_file;
0
- r->canonical_filename = html_file;
0
- forwardToRails = false;
0
+ forwardToApplication = false;
0
+ } else if (r->method_number == M_GET) {
0
+ len = strlen(r->filename);
0
+ if (len > 0 && r->filename[len - 1] == '/') {
0
+ html_file = apr_pstrcat(r->pool, r->filename, "index.html", NULL);
0
+ html_file = apr_pstrcat(r->pool, r->filename, ".html", NULL);
0
+ if (fileExists(html_file)) {
0
+ /* If a .html version of the URI exists, serve it directly.
0
+ * We're essentially accelerating Rails page caching.
0
+ r->filename = html_file;
0
+ r->canonical_filename = html_file;
0
+ forwardToApplication = false;
0
+ forwardToApplication = true;
0
- forwardToRails = true;
0
- * Non-GET requests are always forwarded to Rails.
0
- * This important because of REST conventions, e.g.
0
- * 'POST /foo' maps to 'FooController.create',
0
- * while 'GET /foo' maps to 'FooController.index'.
0
- * We wouldn't want our page caching support to interfere
0
- forwardToRails = true;
0
- /* Apache's default map_to_storage process does strange
0
- * things with the filename. Suppose that the DocumentRoot
0
- * is /website, on server http://test.com/. If we access
0
- * http://test.com/foo/bar, and /website/foo/bar does not
0
- * exist, then Apache will change the filename to
0
- * /website/foo instead of the expected /website/bar.
0
- * We make sure that doesn't happen.
0
- * Incidentally, this also disables mod_rewrite. That is a
0
- * good thing because the default Rails .htaccess file
0
- * interferes with Passenger anyway (it delegates requests
0
- * to the CGI script dispatch.cgi).
0
- if (config->allowModRewrite == DirConfig::UNSET
0
- || config->allowModRewrite == DirConfig::DISABLED) {
0
- /* Of course, we only do that if the config allows us
0
- * to. Some people have complex mod_rewrite rules that
0
- * they don't want to abandon. Those people will have to
0
- * make sure that the Rails app's .htaccess doesn't
0
+ * Non-GET requests are always forwarded to the application.
0
+ * This important because of REST conventions, e.g.
0
+ * 'POST /foo' maps to 'FooController.create',
0
+ * while 'GET /foo' maps to 'FooController.index'.
0
+ * We wouldn't want our page caching support to interfere
0
- } else if (strcmp(r->uri, mapper.getBaseURI()) == 0) {
0
- /* But we ignore RailsAllowModRewrite for the base URI of
0
- * the Rails application. Otherwise, Apache will show a
0
- * directory listing. This fixes issue #11.
0
+ forwardToApplication = true;
0
+ if (forwardToApplication) {
0
+ /* Apache's default map_to_storage process does strange
0
+ * things with the filename. Suppose that the DocumentRoot
0
+ * is /website, on server http://test.com/. If we access
0
+ * http://test.com/foo/bar, and /website/foo/bar does not
0
+ * exist, then Apache will change the filename to
0
+ * /website/foo instead of the expected /website/bar.
0
+ * We make sure that doesn't happen.
0
+ * Incidentally, this also disables mod_rewrite. That is a
0
+ * good thing because the default Rails .htaccess file
0
+ * interferes with Passenger anyway (it delegates requests
0
+ * to the CGI script dispatch.cgi).
0
+ if (config->allowModRewrite != DirConfig::ENABLED
0
+ && mapper.getApplicationType() == DirectoryMapper::RAILS) {
0
+ /* Of course, we only do that if all of the following
0
+ * - the config allows us to. Some people have complex
0
+ * mod_rewrite rules that they don't want to abandon.
0
+ * Those people will have to make sure that the Rails
0
+ * app's .htaccess doesn't interfere.
0
+ * - this is a Rails application.
0
+ } else if (strcmp(r->uri, mapper.getBaseURI()) == 0) {
0
+ /* If the request URI is the application's base URI,
0
+ * then we'll want to take over control. Otherwise,
0
+ * Apache will show a directory listing. This fixes issue #11.
0
+ }
catch (const FileSystemException &e) {
Comments
No one has commented yet.