If you care about the Content-Typr header, how come you're not setting it yourself?
If you care about the Content-Typr header, how come you're not setting it yourself?
fmt.Fprintln(w, "Hello world!" + string(2))
// If the Header does not contain a
// Content-Type line, Write adds a Content-Type set to the result of passing
// the initial 512 bytes of written data to DetectContentType.
package mainimport ("fmt""net/http")func Handler(w http.ResponseWriter, req *http.Request) {w.Header().Set("Content-Type", "text/plain; charset=utf-8")fmt.Fprintln(w, "Hello world!" + string(2))}func main() {http.Handle("/", http.HandlerFunc(Handler))http.ListenAndServe(":8080", nil)}# go run foo.go &# curl -I localhost:8080/HTTP/1.1 200 OKContent-Type: text/plain; charset=utf-8Date: Sat, 14 Jul 2012 00:55:07 GMT
Hi,I can but I don't want to. That's the last thing I wanna worry about when building an application.
Why implement chunked transfer encoding as the default response type if it's not completely functional?
Yes, you are right. That's how HTTP works and I wasn't aware there was so poor support for trailers.Maybe the best solution for Go 1 would be to document this more prominently and centrally in a single chunk of text in the net/http package. For later versions this issue could eventually be revisited and maybe simplified as Peter suggests.For people coming from interpreted web-languages (like me, from PHP) this stuff is being taken care of behind the scenes and it's confusing when we suddenly encounter that cookies are not being set for some reason.
One of the reasons I moved away from PHP is the level of magic and abstraction involved - which makes Go feel very controllable and steady for me.
I just have to find a Go job now and I'll be completely done with PHP :-)