Hi -
I'm new to Go and trying to write a simple web server that supports
chunked transfers. I started with the sample web server from the http
package documentation, but I can't seem to get the Transfer-Encoding
header set to "chunked" no matter what I try.
Here is the code I have so far:
package main
import (
"http"
"log"
)
func MyServer(writer http.ResponseWriter, req *http.Request) {
writer.SetHeader("Transfer-Encoding", "chunked")
writeCloser := http.NewChunkedWriter(writer)
msg := []byte("Testing\n")
writeCloser.Write(msg)
writeCloser.Close()
}
func main() {
http.HandleFunc("/", MyServer)
error := http.ListenAndServe(":9999", nil)
if error != nil {
log.Exit("ListenAndServe: ", error.String())
}
}
When I hit
http://localhost:9999, I see the output I would expect in
the body, but the Transfer-Encoding header is still set to "Identity",
not "chunked".
What's the right way to go about doing this? Thanks in advance for
any help.