mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 14:10: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
|
UseFcgi bool
|
||||||
MaxMemory int64
|
MaxMemory int64
|
||||||
EnableGzip bool // enable gzip
|
EnableGzip bool // enable gzip
|
||||||
|
DirectoryIndex bool //ebable DirectoryIndex default is false
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -174,6 +174,9 @@ func ParseConfig() (err error) {
|
|||||||
if ar, err := AppConfig.Bool("enablegzip"); err == nil {
|
if ar, err := AppConfig.Bool("enablegzip"); err == nil {
|
||||||
EnableGzip = ar
|
EnableGzip = ar
|
||||||
}
|
}
|
||||||
|
if ar, err := AppConfig.Bool("directoryindex"); err == nil {
|
||||||
|
DirectoryIndex = ar
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
16
router.go
16
router.go
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -317,6 +318,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
}
|
}
|
||||||
if strings.HasPrefix(r.URL.Path, prefix) {
|
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||||
file := staticDir + r.URL.Path[len(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)
|
http.ServeFile(w, r, file)
|
||||||
w.started = true
|
w.started = true
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user