mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:50:54 +00:00
fix #81
This commit is contained in:
parent
3578bb3287
commit
c5a23d5cde
1
beego.go
1
beego.go
@ -39,6 +39,7 @@ var (
|
||||
UseFcgi bool
|
||||
MaxMemory int64
|
||||
EnableGzip bool // enable gzip
|
||||
DirectoryIndex bool //ebable DirectoryIndex default is false
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -174,6 +174,9 @@ func ParseConfig() (err error) {
|
||||
if ar, err := AppConfig.Bool("enablegzip"); err == nil {
|
||||
EnableGzip = ar
|
||||
}
|
||||
if ar, err := AppConfig.Bool("directoryindex"); err == nil {
|
||||
DirectoryIndex = ar
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
16
router.go
16
router.go
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"runtime"
|
||||
@ -317,6 +318,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
||||
}
|
||||
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||
file := staticDir + r.URL.Path[len(prefix):]
|
||||
finfo, err := os.Stat(file)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
//if the request is dir and DirectoryIndex is false then
|
||||
if finfo.IsDir() && !DirectoryIndex {
|
||||
if h, ok := ErrorMaps["403"]; ok {
|
||||
h(w, r)
|
||||
} else {
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
w.WriteHeader(403)
|
||||
fmt.Fprintln(w, "403 Forbidden")
|
||||
return
|
||||
}
|
||||
}
|
||||
http.ServeFile(w, r, file)
|
||||
w.started = true
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user