go - how to avoid sending Content-Length header -



go - how to avoid sending Content-Length header -

for streaming http endpoint there way refrain sending length?

w.header().set("content-type", "image/jpeg") w.header().set("transfer-encoding", "chunked") w.header().del("content-length")

this back.

http/1.1 200 ok content-length: 0 content-type: image/jpeg date: mon, 23 jun 2014 10:00:59 gmt transfer-encoding: chunked transfer-encoding: chunked

the server prints warning well.

2014/06/23 06:04:03 http: writeheader called both transfer-encoding of "chunked" , content-length of 0

you should not manually set transfer-encoding. go going you, content-length.

curl, go http client or standard http client automatically read correctly chunked or non-chunked http response.

small exmaple of chunked server: http://play.golang.org/p/miev7uri8p

package main import ( "io" "log" "net/http" ) // hello world, web server func helloserver(w http.responsewriter, req *http.request) { w.writeheader(200) := 0; < 5; i++ { io.writestring(w, "hello, world!\n") w.(http.flusher).flush() } } func main() { http.handlefunc("/", helloserver) err := http.listenandserve(":8080", nil) if err != nil { log.fatal("listenandserve: ", err) } }

in case of image/jpeg, can either delegate chunked decision go or manually send n bytes image flush.

go

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -