43057a2f by astaxie

fix #284

1 parent 9446563e
...@@ -461,6 +461,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -461,6 +461,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
461 file := staticDir + r.URL.Path[len(prefix):] 461 file := staticDir + r.URL.Path[len(prefix):]
462 finfo, err := os.Stat(file) 462 finfo, err := os.Stat(file)
463 if err != nil { 463 if err != nil {
464 Warn(err)
465 http.NotFound(w, r)
464 return 466 return
465 } 467 }
466 //if the request is dir and DirectoryIndex is false then 468 //if the request is dir and DirectoryIndex is false then
......
1 package beego 1 package beego
2 2
3 import ( 3 import (
4 "io/ioutil"
5 "net/http" 4 "net/http"
6 "net/http/httptest" 5 "net/http/httptest"
7 "os"
8 "testing" 6 "testing"
9 ) 7 )
10 8
...@@ -143,16 +141,13 @@ func TestNotFound(t *testing.T) { ...@@ -143,16 +141,13 @@ func TestNotFound(t *testing.T) {
143 // TestStatic tests the ability to serve static 141 // TestStatic tests the ability to serve static
144 // content from the filesystem 142 // content from the filesystem
145 func TestStatic(t *testing.T) { 143 func TestStatic(t *testing.T) {
146 r, _ := http.NewRequest("GET", "/router_test.go", nil) 144 r, _ := http.NewRequest("GET", "/static/js/jquery.js", nil)
147 w := httptest.NewRecorder() 145 w := httptest.NewRecorder()
148 pwd, _ := os.Getwd()
149 146
150 handler := NewControllerRegistor() 147 handler := NewControllerRegistor()
151 SetStaticPath("/", pwd)
152 handler.ServeHTTP(w, r) 148 handler.ServeHTTP(w, r)
153 149
154 testFile, _ := ioutil.ReadFile(pwd + "/routes_test.go") 150 if w.Code != 404 {
155 if w.Body.String() != string(testFile) {
156 t.Errorf("handler.Static failed to serve file") 151 t.Errorf("handler.Static failed to serve file")
157 } 152 }
158 } 153 }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!