4ce584c5 by astaxie

fix #201

1 parent 3c1d23bc
...@@ -311,7 +311,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -311,7 +311,6 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
311 311
312 params := make(map[string]string) 312 params := make(map[string]string)
313 313
314 context.Input.Param = params
315 if p.enableFilter { 314 if p.enableFilter {
316 if l, ok := p.filters["BeforRouter"]; ok { 315 if l, ok := p.filters["BeforRouter"]; ok {
317 for _, filterR := range l { 316 for _, filterR := range l {
...@@ -412,6 +411,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -412,6 +411,7 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
412 break 411 break
413 } 412 }
414 } 413 }
414 context.Input.Param = params
415 415
416 if runrouter != nil { 416 if runrouter != nil {
417 if r.Method == "POST" { 417 if r.Method == "POST" {
...@@ -584,6 +584,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -584,6 +584,14 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
584 584
585 if p.enableAuto { 585 if p.enableAuto {
586 if !findrouter { 586 if !findrouter {
587 lastindex := strings.LastIndex(requestPath, "/")
588 lastsub := requestPath[lastindex+1:]
589 if subindex := strings.LastIndex(lastsub, "."); subindex != -1 {
590 context.Input.Param[":ext"] = lastsub[subindex+1:]
591 r.URL.Query().Add(":ext", lastsub[subindex+1:])
592 r.URL.RawQuery = r.URL.Query().Encode()
593 requestPath = requestPath[:len(requestPath)-len(lastsub[subindex:])]
594 }
587 for cName, methodmap := range p.autoRouter { 595 for cName, methodmap := range p.autoRouter {
588 596
589 if strings.ToLower(requestPath) == "/"+cName { 597 if strings.ToLower(requestPath) == "/"+cName {
......
...@@ -21,6 +21,10 @@ func (this *TestController) List() { ...@@ -21,6 +21,10 @@ func (this *TestController) List() {
21 this.Ctx.Output.Body([]byte("i am list")) 21 this.Ctx.Output.Body([]byte("i am list"))
22 } 22 }
23 23
24 func (this *TestController) Myext() {
25 this.Ctx.Output.Body([]byte(this.Ctx.Input.Params(":ext")))
26 }
27
24 func TestUserFunc(t *testing.T) { 28 func TestUserFunc(t *testing.T) {
25 r, _ := http.NewRequest("GET", "/api/list", nil) 29 r, _ := http.NewRequest("GET", "/api/list", nil)
26 w := httptest.NewRecorder() 30 w := httptest.NewRecorder()
...@@ -45,6 +49,18 @@ func TestAutoFunc(t *testing.T) { ...@@ -45,6 +49,18 @@ func TestAutoFunc(t *testing.T) {
45 } 49 }
46 } 50 }
47 51
52 func TestAutoExtFunc(t *testing.T) {
53 r, _ := http.NewRequest("GET", "/test/myext.json", nil)
54 w := httptest.NewRecorder()
55
56 handler := NewControllerRegistor()
57 handler.AddAuto(&TestController{})
58 handler.ServeHTTP(w, r)
59 if w.Body.String() != "json" {
60 t.Errorf("user define func can't run")
61 }
62 }
63
48 func TestRouteOk(t *testing.T) { 64 func TestRouteOk(t *testing.T) {
49 65
50 r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil) 66 r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil)
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!