I have the following server code:
package main
import (
"fmt"
"net/http"
"time"
)
type serveData struct {
}
func (s *serveData) Read (p []byte) (int, error) {
l := len (p)
fmt.Println ("p size is ", l);
time.Sleep(200 * time.Millisecond);
return l, nil;
}
func (s *serveData) Seek (offset int64, whence int) (int64, error) {
fmt.Println ("in seek ", offset);
return offset, nil;
}
func handler(w http.ResponseWriter, r *http.Request) {
reader := new (serveData)
//w.WriteHeader(206);
w.Header().Set("Content-type", "application/octet-stream");
fmt.Println ("got request");
http.ServeContent(w, r, "cool", time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC), reader)
}
func main() {
http.HandleFunc("/check", handler)
http.ListenAndServe(":8080", nil)
}
When i connect the client to the server above (curl -X GET http://127.0.0.1:8080/check
), nothing happens and curl just exits. The server calls Seek()
function 2 times, but never calls Read()
I am serving partial content, as the size is unbounded (pseudo-live data). Also, when I uncomment w.WriteHeader(206)
, the server complains about "http: multiple response.WriteHeader calls
"
What possibly is going wrong here?