mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 19:50:56 +00:00
Update router.go
This commit is contained in:
parent
02eacb8e95
commit
9995168f9a
45
router.go
45
router.go
@ -473,7 +473,39 @@ func (p *ControllerRegistor) ServeHTTP(rw http.ResponseWriter, r *http.Request)
|
|||||||
middleware.Exception("403", rw, r, "403 Forbidden")
|
middleware.Exception("403", rw, r, "403 Forbidden")
|
||||||
goto Admin
|
goto Admin
|
||||||
}
|
}
|
||||||
http.ServeFile(w, r, file)
|
|
||||||
|
//This block obtained from (https://github.com/smithfox/beego) - it should probably get merged into astaxie/beego after a pull request
|
||||||
|
isStaticFileToCompress := false
|
||||||
|
if StaticExtensionsToGzip != nil && len(StaticExtensionsToGzip) > 0 {
|
||||||
|
for _, statExtension := range StaticExtensionsToGzip {
|
||||||
|
if strings.HasSuffix(strings.ToLower(file), strings.ToLower(statExtension)) {
|
||||||
|
isStaticFileToCompress = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if isStaticFileToCompress {
|
||||||
|
if EnableGzip {
|
||||||
|
w.contentEncoding = GetAcceptEncodingZip(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
memzipfile, err := OpenMemZipFile(file, w.contentEncoding)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.InitHeadContent(finfo.Size())
|
||||||
|
|
||||||
|
if strings.HasSuffix(file, ".mustache") {
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8") //FIXME: hardcode
|
||||||
|
}
|
||||||
|
|
||||||
|
http.ServeContent(w, r, file, finfo.ModTime(), memzipfile)
|
||||||
|
} else {
|
||||||
|
http.ServeFile(w, r, file)
|
||||||
|
}
|
||||||
|
|
||||||
w.started = true
|
w.started = true
|
||||||
goto Admin
|
goto Admin
|
||||||
}
|
}
|
||||||
@ -901,6 +933,7 @@ type responseWriter struct {
|
|||||||
writer http.ResponseWriter
|
writer http.ResponseWriter
|
||||||
started bool
|
started bool
|
||||||
status int
|
status int
|
||||||
|
contentEncoding string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Header returns the header map that will be sent by WriteHeader.
|
// Header returns the header map that will be sent by WriteHeader.
|
||||||
@ -908,6 +941,16 @@ func (w *responseWriter) Header() http.Header {
|
|||||||
return w.writer.Header()
|
return w.writer.Header()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *responseWriter) InitHeadContent(contentlength int64) {
|
||||||
|
if w.contentEncoding == "gzip" {
|
||||||
|
w.Header().Set("Content-Encoding", "gzip")
|
||||||
|
} else if w.contentEncoding == "deflate" {
|
||||||
|
w.Header().Set("Content-Encoding", "deflate")
|
||||||
|
} else {
|
||||||
|
w.Header().Set("Content-Length", strconv.FormatInt(contentlength, 10))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Write writes the data to the connection as part of an HTTP reply,
|
// Write writes the data to the connection as part of an HTTP reply,
|
||||||
// and sets `started` to true
|
// and sets `started` to true
|
||||||
func (w *responseWriter) Write(p []byte) (int, error) {
|
func (w *responseWriter) Write(p []byte) (int, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user