mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 20:00:54 +00:00
fix #284
This commit is contained in:
parent
9446563e5b
commit
43057a2fcb
@ -461,6 +461,8 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
file := staticDir + r.URL.Path[len(prefix):]
|
file := staticDir + r.URL.Path[len(prefix):]
|
||||||
finfo, err := os.Stat(file)
|
finfo, err := os.Stat(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Warn(err)
|
||||||
|
http.NotFound(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//if the request is dir and DirectoryIndex is false then
|
//if the request is dir and DirectoryIndex is false then
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package beego
|
package beego
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"os"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -143,16 +141,13 @@ func TestNotFound(t *testing.T) {
|
|||||||
// TestStatic tests the ability to serve static
|
// TestStatic tests the ability to serve static
|
||||||
// content from the filesystem
|
// content from the filesystem
|
||||||
func TestStatic(t *testing.T) {
|
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()
|
w := httptest.NewRecorder()
|
||||||
pwd, _ := os.Getwd()
|
|
||||||
|
|
||||||
handler := NewControllerRegistor()
|
handler := NewControllerRegistor()
|
||||||
SetStaticPath("/", pwd)
|
|
||||||
handler.ServeHTTP(w, r)
|
handler.ServeHTTP(w, r)
|
||||||
|
|
||||||
testFile, _ := ioutil.ReadFile(pwd + "/routes_test.go")
|
if w.Code != 404 {
|
||||||
if w.Body.String() != string(testFile) {
|
|
||||||
t.Errorf("handler.Static failed to serve file")
|
t.Errorf("handler.Static failed to serve file")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user