Endpoint registering '/ep' will no longer match '/ep/x'.

Trailing slashes removed. So '/ep/' will become '/ep'.
This commit is contained in:
high 2011-09-05 15:06:08 -04:00
parent f949738db9
commit 7ae6910853
2 changed files with 6 additions and 3 deletions

View file

@ -79,12 +79,15 @@ namespace Rests
protected virtual object ProcessRequest(object sender, RequestEventArgs e)
{
var uri = e.Request.Uri.AbsolutePath;
uri = uri.TrimEnd('/');
foreach (var com in commands)
{
var verbs = new RestVerbs();
if (com.HasVerbs)
{
var match = Regex.Match(e.Request.Uri.AbsolutePath, com.UriVerbMatch);
var match = Regex.Match(uri, com.UriVerbMatch);
if (!match.Success)
continue;
if ((match.Groups.Count - 1) != com.UriVerbs.Length)
@ -93,7 +96,7 @@ namespace Rests
for (int i = 0; i < com.UriVerbs.Length; i++)
verbs.Add(com.UriVerbs[i], match.Groups[i + 1].Value);
}
else if (com.UriTemplate.ToLower() != e.Request.Uri.AbsolutePath.ToLower())
else if (com.UriTemplate.ToLower() != uri.ToLower())
{
continue;
}

View file

@ -22,7 +22,7 @@ namespace Rests
{
Name = name;
UriTemplate = uritemplate;
UriVerbMatch = string.Join("([^/]*)", Regex.Split(uritemplate, "\\{[^\\{\\}]*\\}"));
UriVerbMatch = string.Format("^{0}$", string.Join("([^/]*)", Regex.Split(uritemplate, "\\{[^\\{\\}]*\\}")));
var matches = Regex.Matches(uritemplate, "\\{([^\\{\\}]*)\\}");
UriVerbs = (from Match match in matches select match.Groups[1].Value).ToArray();
Callback = callback;