diff --git a/restws.module b/restws.module index 66eee17..37812ba 100644 --- a/restws.module +++ b/restws.module @@ -195,7 +195,8 @@ class RestWSException extends Exception { * Sets the router item for the current path when it has a format. */ function restws_init() { - _restws_reroute_format_requests(); + // Determine the router item for the current path. + _restws_determine_router_item(); } /** @@ -206,7 +207,8 @@ function restws_init() { * Also, the restws_basic_auth module will need to use this function as well * to perform this again after logging a user in. */ -function _restws_reroute_format_requests() { +function _restws_determine_router_item() { + // Determine the position of the resource and resource id in the path. if (strpos(request_path(), '.') === FALSE) { return; } @@ -216,10 +218,14 @@ function _restws_reroute_format_requests() { } $formats = array_keys(restws_get_format_info()); + // The pattern matches menu paths like 'node', 'user' followed by an ID. + // This ID cannot start with a 0 but can contain any digit. $pattern = '#^((?:'; $pattern .= implode($menu_paths,'|'); $pattern .= ')\/[1-9][0-9]*)\.(?:'; + // The path will end with a format that is supported by restws, for example + // 'json' or 'xml'. $pattern .= implode($formats,'|'); $pattern .= ')$#i'; diff --git a/restws_basic_auth/restws_basic_auth.module b/restws_basic_auth/restws_basic_auth.module index fc8de43..dfb0cdd 100644 --- a/restws_basic_auth/restws_basic_auth.module +++ b/restws_basic_auth/restws_basic_auth.module @@ -34,9 +34,9 @@ function restws_basic_auth_init() { // user so that a response never gets into the page cache. drupal_page_is_cacheable(FALSE); - // Because we need to redetermine the page callback for - // /node/{id}.{format} calls, we call this. - _restws_reroute_format_requests(); + // Redetermine the page callback for restws calls like node/1.json + // and user/1.json. + _restws_determine_router_item(); } else { // Clear the login form error and remove the login failure message.