1
0
mirror of https://github.com/astaxie/beego.git synced 2024-06-18 12:04:13 +00:00
This commit is contained in:
astaxie 2013-06-24 23:24:13 +08:00
parent 3578bb3287
commit c5a23d5cde
3 changed files with 20 additions and 0 deletions

View File

@ -39,6 +39,7 @@ var (
UseFcgi bool
MaxMemory int64
EnableGzip bool // enable gzip
DirectoryIndex bool //ebable DirectoryIndex default is false
)
func init() {

View File

@ -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
}

View File

@ -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