aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/emicklei/go-restful/route.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/emicklei/go-restful/route.go')
-rw-r--r--vendor/github.com/emicklei/go-restful/route.go50
1 files changed, 2 insertions, 48 deletions
diff --git a/vendor/github.com/emicklei/go-restful/route.go b/vendor/github.com/emicklei/go-restful/route.go
index b9e346a5e..f72bf9850 100644
--- a/vendor/github.com/emicklei/go-restful/route.go
+++ b/vendor/github.com/emicklei/go-restful/route.go
@@ -5,7 +5,6 @@ package restful
// that can be found in the LICENSE file.
import (
- "bytes"
"net/http"
"strings"
)
@@ -54,10 +53,9 @@ func (r *Route) postBuild() {
}
// Create Request and Response from their http versions
-func (r *Route) wrapRequestResponse(httpWriter http.ResponseWriter, httpRequest *http.Request) (*Request, *Response) {
- params := r.extractParameters(httpRequest.URL.Path)
+func (r *Route) wrapRequestResponse(httpWriter http.ResponseWriter, httpRequest *http.Request, pathParams map[string]string) (*Request, *Response) {
wrappedRequest := NewRequest(httpRequest)
- wrappedRequest.pathParameters = params
+ wrappedRequest.pathParameters = pathParams
wrappedRequest.selectedRoutePath = r.Path
wrappedResponse := NewResponse(httpWriter)
wrappedResponse.requestAccept = httpRequest.Header.Get(HEADER_Accept)
@@ -137,50 +135,6 @@ func (r Route) matchesContentType(mimeTypes string) bool {
return false
}
-// Extract the parameters from the request url path
-func (r Route) extractParameters(urlPath string) map[string]string {
- urlParts := tokenizePath(urlPath)
- pathParameters := map[string]string{}
- for i, key := range r.pathParts {
- var value string
- if i >= len(urlParts) {
- value = ""
- } else {
- value = urlParts[i]
- }
- if strings.HasPrefix(key, "{") { // path-parameter
- if colon := strings.Index(key, ":"); colon != -1 {
- // extract by regex
- regPart := key[colon+1 : len(key)-1]
- keyPart := key[1:colon]
- if regPart == "*" {
- pathParameters[keyPart] = untokenizePath(i, urlParts)
- break
- } else {
- pathParameters[keyPart] = value
- }
- } else {
- // without enclosing {}
- pathParameters[key[1:len(key)-1]] = value
- }
- }
- }
- return pathParameters
-}
-
-// Untokenize back into an URL path using the slash separator
-func untokenizePath(offset int, parts []string) string {
- var buffer bytes.Buffer
- for p := offset; p < len(parts); p++ {
- buffer.WriteString(parts[p])
- // do not end
- if p < len(parts)-1 {
- buffer.WriteString("/")
- }
- }
- return buffer.String()
-}
-
// Tokenize an URL path using the slash separator ; the result does not have empty tokens
func tokenizePath(path string) []string {
if "/" == path {