I added a Boolean to the that if set to true, extracts the RawPath from the URL.

This commit is contained in:
jaceshim 2016-06-09 17:28:36 +09:00
parent f931d1ea80
commit bb2a73c900

5
gin.go
View File

@ -78,6 +78,7 @@ type (
// handler. // handler.
HandleMethodNotAllowed bool HandleMethodNotAllowed bool
ForwardedByClientIP bool ForwardedByClientIP bool
UseRawPath bool
} }
) )
@ -102,6 +103,7 @@ func New() *Engine {
HandleMethodNotAllowed: false, HandleMethodNotAllowed: false,
ForwardedByClientIP: true, ForwardedByClientIP: true,
trees: make(methodTrees, 0, 9), trees: make(methodTrees, 0, 9),
UseRawPath: false,
} }
engine.RouterGroup.engine = engine engine.RouterGroup.engine = engine
engine.pool.New = func() interface{} { engine.pool.New = func() interface{} {
@ -270,6 +272,9 @@ func (engine *Engine) ServeHTTP(w http.ResponseWriter, req *http.Request) {
func (engine *Engine) handleHTTPRequest(context *Context) { func (engine *Engine) handleHTTPRequest(context *Context) {
httpMethod := context.Request.Method httpMethod := context.Request.Method
path := context.Request.URL.Path path := context.Request.URL.Path
if (engine.UseRawPath && len(context.Request.URL.RawPath) > 0 ) {
path = context.Request.URL.RawPath
}
// Find root of the tree for the given HTTP method // Find root of the tree for the given HTTP method
t := engine.trees t := engine.trees