astaxie / beegae

beego for GAE
Other
38 stars 11 forks source link

beegae's BeegoInput.RequestBody is empty until BeegoInput.CopyBody() is called #22

Closed nedn closed 9 years ago

nedn commented 9 years ago

I make a post request handler as follows (MainController is beegae.Controller) : func (this *MainController) Post() { var object models.Object // debug(this, string(this.Ctx.Input.CopyBody())) err := json.Unmarshal(this.Ctx.Input.RequestBody, &object) if err != nil { debug(this, "Error "+err.Error()) this.Data["json"] = err return } t, err := object.Save(this.AppEngineCtx) if err != nil { debug(this, err.Error()) this.Data["json"] = err } else { this.Data["json"] = &t } }

Without the line // debug(this, string(this.Ctx.Input.CopyBody())), I got the "Error unexpected end of JSON input".

When I look into the implementation of beegae/context/input.go, I found RequestBody field is only set in CopyBody() method (https://github.com/astaxie/beego/blob/master/context/input.go#L270). Is this intentional that RequestBody is only set by calling CopyBody()?

someone1 commented 9 years ago

It is intentional: https://github.com/astaxie/beego/blob/master/config.go#L72

This is a beego configuration flag.