mirror of
https://github.com/astaxie/beego.git
synced 2024-11-26 17:01:28 +00:00
commit
a7452388d9
6
beego.go
6
beego.go
@ -85,9 +85,11 @@ func initBeforeHTTPRun() {
|
|||||||
|
|
||||||
// TestBeegoInit is for test package init
|
// TestBeegoInit is for test package init
|
||||||
func TestBeegoInit(ap string) {
|
func TestBeegoInit(ap string) {
|
||||||
os.Setenv("BEEGO_RUNMODE", "test")
|
|
||||||
appConfigPath = filepath.Join(ap, "conf", "app.conf")
|
appConfigPath = filepath.Join(ap, "conf", "app.conf")
|
||||||
os.Chdir(ap)
|
os.Chdir(ap)
|
||||||
LoadAppConfig(appConfigProvider, appConfigPath)
|
if err := LoadAppConfig(appConfigProvider, appConfigPath); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
BConfig.RunMode = "test"
|
||||||
initBeforeHTTPRun()
|
initBeforeHTTPRun()
|
||||||
}
|
}
|
||||||
|
@ -274,7 +274,7 @@ func assignConfig(ac config.Configer) error {
|
|||||||
for adaptor, config := range BConfig.Log.Outputs {
|
for adaptor, config := range BConfig.Log.Outputs {
|
||||||
err := logs.SetLogger(adaptor, config)
|
err := logs.SetLogger(adaptor, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "%s with the config `%s` got err:%s\n", adaptor, config, err)
|
fmt.Fprintln(os.Stderr, fmt.Sprintf("%s with the config %q got err:%s", adaptor, config, err.Error()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logs.SetLogFuncCall(BConfig.Log.FileLineNum)
|
logs.SetLogFuncCall(BConfig.Log.FileLineNum)
|
||||||
|
@ -24,6 +24,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"mime"
|
"mime"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -244,13 +245,15 @@ func (output *BeegoOutput) Download(file string, filename ...string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var fName string
|
||||||
|
if len(filename) > 0 && filename[0] != "" {
|
||||||
|
fName = filename[0]
|
||||||
|
} else {
|
||||||
|
fName = filepath.Base(file)
|
||||||
|
}
|
||||||
|
output.Header("Content-Disposition", "attachment; filename="+url.QueryEscape(fName))
|
||||||
output.Header("Content-Description", "File Transfer")
|
output.Header("Content-Description", "File Transfer")
|
||||||
output.Header("Content-Type", "application/octet-stream")
|
output.Header("Content-Type", "application/octet-stream")
|
||||||
if len(filename) > 0 && filename[0] != "" {
|
|
||||||
output.Header("Content-Disposition", "attachment; filename="+filename[0])
|
|
||||||
} else {
|
|
||||||
output.Header("Content-Disposition", "attachment; filename="+filepath.Base(file))
|
|
||||||
}
|
|
||||||
output.Header("Content-Transfer-Encoding", "binary")
|
output.Header("Content-Transfer-Encoding", "binary")
|
||||||
output.Header("Expires", "0")
|
output.Header("Expires", "0")
|
||||||
output.Header("Cache-Control", "must-revalidate")
|
output.Header("Cache-Control", "must-revalidate")
|
||||||
|
@ -132,17 +132,13 @@ func NewManager(provideName, config string) (*Manager, error) {
|
|||||||
|
|
||||||
if cf.EnableSidInHttpHeader {
|
if cf.EnableSidInHttpHeader {
|
||||||
if cf.SessionNameInHttpHeader == "" {
|
if cf.SessionNameInHttpHeader == "" {
|
||||||
err = errors.New("SessionNameInHttpHeader is empty")
|
panic(errors.New("SessionNameInHttpHeader is empty"))
|
||||||
panic(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
strMimeHeader := textproto.CanonicalMIMEHeaderKey(cf.SessionNameInHttpHeader)
|
strMimeHeader := textproto.CanonicalMIMEHeaderKey(cf.SessionNameInHttpHeader)
|
||||||
if cf.SessionNameInHttpHeader != strMimeHeader {
|
if cf.SessionNameInHttpHeader != strMimeHeader {
|
||||||
strErrMsg := "SessionNameInHttpHeader (" + cf.SessionNameInHttpHeader + ") has the wrong format, it should be like this : " + strMimeHeader
|
strErrMsg := "SessionNameInHttpHeader (" + cf.SessionNameInHttpHeader + ") has the wrong format, it should be like this : " + strMimeHeader
|
||||||
err = errors.New(strErrMsg)
|
panic(errors.New(strErrMsg))
|
||||||
panic(err)
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user