c5a23d5c by astaxie

fix #81

1 parent 3578bb32
...@@ -39,6 +39,7 @@ var ( ...@@ -39,6 +39,7 @@ var (
39 UseFcgi bool 39 UseFcgi bool
40 MaxMemory int64 40 MaxMemory int64
41 EnableGzip bool // enable gzip 41 EnableGzip bool // enable gzip
42 DirectoryIndex bool //ebable DirectoryIndex default is false
42 ) 43 )
43 44
44 func init() { 45 func init() {
......
...@@ -174,6 +174,9 @@ func ParseConfig() (err error) { ...@@ -174,6 +174,9 @@ func ParseConfig() (err error) {
174 if ar, err := AppConfig.Bool("enablegzip"); err == nil { 174 if ar, err := AppConfig.Bool("enablegzip"); err == nil {
175 EnableGzip = ar 175 EnableGzip = ar
176 } 176 }
177 if ar, err := AppConfig.Bool("directoryindex"); err == nil {
178 DirectoryIndex = ar
179 }
177 } 180 }
178 return nil 181 return nil
179 } 182 }
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
4 "fmt" 4 "fmt"
5 "net/http" 5 "net/http"
6 "net/url" 6 "net/url"
7 "os"
7 "reflect" 8 "reflect"
8 "regexp" 9 "regexp"
9 "runtime" 10 "runtime"
...@@ -317,6 +318,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request) ...@@ -317,6 +318,21 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
317 } 318 }
318 if strings.HasPrefix(r.URL.Path, prefix) { 319 if strings.HasPrefix(r.URL.Path, prefix) {
319 file := staticDir + r.URL.Path[len(prefix):] 320 file := staticDir + r.URL.Path[len(prefix):]
321 finfo, err := os.Stat(file)
322 if err != nil {
323 return
324 }
325 //if the request is dir and DirectoryIndex is false then
326 if finfo.IsDir() && !DirectoryIndex {
327 if h, ok := ErrorMaps["403"]; ok {
328 h(w, r)
329 } else {
330 w.Header().Set("Content-Type", "text/plain; charset=utf-8")
331 w.WriteHeader(403)
332 fmt.Fprintln(w, "403 Forbidden")
333 return
334 }
335 }
320 http.ServeFile(w, r, file) 336 http.ServeFile(w, r, file)
321 w.started = true 337 w.started = true
322 return 338 return
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!