mirror of
https://gitee.com/johng/gf
synced 2026-06-07 02:12:11 +08:00
fix issue missing build-in variable Request for template parsing of ghttp.Response
This commit is contained in:
@ -84,6 +84,7 @@ func (r *Response) buildInVars(params ...map[string]interface{}) map[string]inte
|
||||
gutil.MapMerge(m, map[string]interface{}{
|
||||
"Form": r.Request.GetFormMap(),
|
||||
"Query": r.Request.GetQueryMap(),
|
||||
"Request": r.Request.GetMap(),
|
||||
"Cookie": r.Request.Cookie.Map(),
|
||||
"Session": r.Request.Session.Map(),
|
||||
})
|
||||
|
||||
@ -139,6 +139,27 @@ func Test_Template_Layout2(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Template_BuildInVarRequest(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
p, _ := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
s.BindHandler("/:table/test", func(r *ghttp.Request) {
|
||||
err := r.Response.WriteTplContent("{{.Request.table}}")
|
||||
t.Assert(err, nil)
|
||||
})
|
||||
s.SetDumpRouterMap(false)
|
||||
s.SetPort(p)
|
||||
s.Start()
|
||||
defer s.Shutdown()
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
client := g.Client()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
|
||||
t.Assert(client.GetContent("/user/test"), "user")
|
||||
t.Assert(client.GetContent("/order/test"), "order")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Template_XSS(t *testing.T) {
|
||||
gtest.C(t, func(t *gtest.T) {
|
||||
v := gview.New()
|
||||
|
||||
Reference in New Issue
Block a user