stretchr / goweb

A lightweight RESTful web framework for Go
632 stars 61 forks source link

Wrong encoding if use Controllers #41

Open bosom opened 11 years ago

bosom commented 11 years ago

If use Controllers and set custom encoding, encoding don't work Example:

goweb.MapBefore(func(c context.Context) error {
   // add a custom header
   c.HttpResponseWriter().Header().Set(`Content-Type`, `application/json; charset=UTF-8`)
   return nil
})

Bugfix this: File: goweb/responders/goweb_api_responders.go

@@ -118,7 +118,9 @@ func (a *GowebAPIResponder) WriteResponseObject(ctx context.Context, status int
matryer commented 11 years ago

Are you saying the header isn't properly set?

tylerstillwater commented 11 years ago

Sounds to me like codecs is overwriting it when doing the encoding.

On Jul 30, 2013, at 9:29 AM, Mat Ryer notifications@github.com wrote:

Are you saying the header isn't properly set?

— Reply to this email directly or view it on GitHub.

matryer commented 11 years ago

That sounds right - that's an interesting one. We'll look at how we might solve this.

bosom commented 11 years ago

Temporarily made ​​a patch: from

    // use the HTTP responder to respond
    ctx.HttpResponseWriter().Header().Set("Content-Type", codec.ContentType()) // TODO: test me

to

    // use the HTTP responder to respond
    if ctx.HttpResponseWriter().Header().Get("Content-Type") == "" {
        ctx.HttpResponseWriter().Header().Set("Content-Type", codec.ContentType()) // TODO: test me
    }
matryer commented 11 years ago

What do we think about this as a solution?