diff --git a/router.go b/router.go index b44b6975..f2cf53b0 100644 --- a/router.go +++ b/router.go @@ -461,6 +461,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) file := staticDir + r.URL.Path[len(prefix):] finfo, err := os.Stat(file) if err != nil { + Warn(err) + http.NotFound(w, r) return } //if the request is dir and DirectoryIndex is false then diff --git a/router_test.go b/router_test.go index 7dcbdee1..e3aef727 100644 --- a/router_test.go +++ b/router_test.go @@ -1,10 +1,8 @@ package beego import ( - "io/ioutil" "net/http" "net/http/httptest" - "os" "testing" ) @@ -143,16 +141,13 @@ func TestNotFound(t *testing.T) { // TestStatic tests the ability to serve static // content from the filesystem func TestStatic(t *testing.T) { - r, _ := http.NewRequest("GET", "/router_test.go", nil) + r, _ := http.NewRequest("GET", "/static/js/jquery.js", nil) w := httptest.NewRecorder() - pwd, _ := os.Getwd() handler := NewControllerRegistor() - SetStaticPath("/", pwd) handler.ServeHTTP(w, r) - testFile, _ := ioutil.ReadFile(pwd + "/routes_test.go") - if w.Body.String() != string(testFile) { + if w.Code != 404 { t.Errorf("handler.Static failed to serve file") } }