1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 13:30:56 +00:00

handle trace request must NOT CACHE

https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Cache-Control
This commit is contained in:
JessonChan 2019-03-27 13:40:34 +08:00
parent e8b29c9fd1
commit 02bead5097

View File

@ -93,17 +93,17 @@ func (p ControllerCommentsSlice) Swap(i, j int) {
// Controller defines some basic http request handler operations, such as // Controller defines some basic http request handler operations, such as
// http context, template and view, session and xsrf. // http context, template and view, session and xsrf.
type Controller struct { type Controller struct {
// context data // context data
Ctx *context.Context Ctx *context.Context
Data map[interface{}]interface{} Data map[interface{}]interface{}
// route controller info // route controller info
controllerName string controllerName string
actionName string actionName string
methodMapping map[string]func() //method:routertree methodMapping map[string]func() //method:routertree
AppController interface{} AppController interface{}
// template data // template data
TplName string TplName string
ViewPath string ViewPath string
Layout string Layout string
@ -112,13 +112,13 @@ type Controller struct {
TplExt string TplExt string
EnableRender bool EnableRender bool
// xsrf data // xsrf data
_xsrfToken string _xsrfToken string
XSRFExpire int XSRFExpire int
EnableXSRF bool EnableXSRF bool
// session // session
CruSession session.Store CruSession session.Store
} }
// ControllerInterface is an interface to uniform all controller handler. // ControllerInterface is an interface to uniform all controller handler.
@ -214,6 +214,7 @@ func (c *Controller) Trace() {
hs := fmt.Sprintf("\r\nTRACE %s %s%s\r\n", c.Ctx.Request.RequestURI, c.Ctx.Request.Proto, ts(c.Ctx.Request.Header)) hs := fmt.Sprintf("\r\nTRACE %s %s%s\r\n", c.Ctx.Request.RequestURI, c.Ctx.Request.Proto, ts(c.Ctx.Request.Header))
c.Ctx.Output.Header("Content-Type", "message/http") c.Ctx.Output.Header("Content-Type", "message/http")
c.Ctx.Output.Header("Content-Length", fmt.Sprint(len(hs))) c.Ctx.Output.Header("Content-Length", fmt.Sprint(len(hs)))
c.Ctx.Output.Header("Cache-Control", "no-cache, no-store, must-revalidate")
c.Ctx.WriteString(hs) c.Ctx.WriteString(hs)
} }
@ -371,7 +372,7 @@ func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
return "" return ""
} }
if endpoint[0] == '.' { if endpoint[0] == '.' {
return URLFor(reflect.Indirect(reflect.ValueOf(c.AppController)).Type().Name() + endpoint, values...) return URLFor(reflect.Indirect(reflect.ValueOf(c.AppController)).Type().Name()+endpoint, values...)
} }
return URLFor(endpoint, values...) return URLFor(endpoint, values...)
} }
@ -379,7 +380,7 @@ func (c *Controller) URLFor(endpoint string, values ...interface{}) string {
// ServeJSON sends a json response with encoding charset. // ServeJSON sends a json response with encoding charset.
func (c *Controller) ServeJSON(encoding ...bool) { func (c *Controller) ServeJSON(encoding ...bool) {
var ( var (
hasIndent = BConfig.RunMode != PROD hasIndent = BConfig.RunMode != PROD
hasEncoding = len(encoding) > 0 && encoding[0] hasEncoding = len(encoding) > 0 && encoding[0]
) )
@ -604,7 +605,7 @@ func (c *Controller) SaveToFile(fromfile, tofile string) error {
return err return err
} }
defer file.Close() defer file.Close()
f, err := os.OpenFile(tofile, os.O_WRONLY | os.O_CREATE | os.O_TRUNC, 0666) f, err := os.OpenFile(tofile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil { if err != nil {
return err return err
} }