go-martini / martini

Classy web framework for Go
martini.codegangsta.io
MIT License
11.63k stars 1.1k forks source link

cannot set headers #427

Closed ORESoftware closed 4 years ago

ORESoftware commented 4 years ago

I am trying to set a custom header: https://stackoverflow.com/questions/60645804/golang-wont-let-me-set-custom-header

the header is being set here:

func (ctr *Controller) Routes(m *martini.ClassicMartini) {
    m.Get("/cp/health/check", common.AsJson, common.RequestTimer, ctr.SimpleJSONResponse)
}

I tried setting it in common.AsJson:

func AsJson(res http.ResponseWriter) {
    //res.Header().Set("cp-auth-token", "eyJhbGciOiJIUzI1NiIs...vVfO3WmqYMHz9TiUXKas")
    res.Header().Set("Content-Type", "application/json")
}

or in ctr.SimpleJSONResponse:

func (ctr *Controller) SimpleJSONResponse(c *common.CPContext, timer common.RequestTime) (int, interface{}) {

    res.Header().Set("cp-auth-token", "eyJhbGciOiJIUzI1NiIs...vVfO3WmqYMHz9TiUXKas")
    return ctr.GenericMarshal(200, HStatus{
        HealthStatus: "ok",
    })

}

nothing seems to work :(

ORESoftware commented 4 years ago

must be some other problem, but prob not martini