about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--dispatcher.go6
-rw-r--r--route.go10
2 files changed, 9 insertions, 7 deletions
diff --git a/dispatcher.go b/dispatcher.go
index a50f2e8..62dee10 100644
--- a/dispatcher.go
+++ b/dispatcher.go
@@ -4,6 +4,7 @@ import (
 	"errors"
 	"fmt"
 	"net/http"
+	"strings"
 )
 
 type Dispatcher struct {
@@ -43,8 +44,11 @@ func (self *Dispatcher) Match(request *http.Request) (*Match, error) {
 
 	matches := []*Match{}
 
+	method := request.Method
+	components := strings.Split(request.URL.Path, "/")
+
 	for _, r := range self.Routes {
-		match := r.Match(request)
+		match := r.Match(method, components)
 		if match != nil {
 			matches = append(matches, match)
 		}
diff --git a/route.go b/route.go
index 832313b..46998c1 100644
--- a/route.go
+++ b/route.go
@@ -1,7 +1,6 @@
 package mooh
 
 import (
-	"net/http"
 	"regexp"
 	"strings"
 )
@@ -36,10 +35,10 @@ func (self *Route) convertComponentName(name string) string {
 	return newName[1]
 }
 
-func (self *Route) Match(request *http.Request) *Match {
+func (self *Route) Match(method string, components []string) *Match {
 	methodMatch := false
 	for m, _ := range self.Executors {
-		if m == request.Method {
+		if m == method {
 			methodMatch = true
 		}
 	}
@@ -47,7 +46,6 @@ func (self *Route) Match(request *http.Request) *Match {
 		return nil
 	}
 
-	components := strings.Split(request.URL.Path, "/")
 	if len(components) < self.LengthWithoutOptional || len(components) > self.Length {
 		return nil
 	}
@@ -70,9 +68,9 @@ func (self *Route) Match(request *http.Request) *Match {
 	}
 
 	return &Match{
-		Path:    request.URL.Path,
+		Path:    strings.Join(components, "/"),
 		Route:   *self,
-		Method:  request.Method,
+		Method:  method,
 		Mapping: mapping,
 	}
 }