All,
I got puzzled by how to read a response size > 32KBytes from http resp.Body. All I get is 32768 bytes. With either io.Read functions or bufio.Reader.
buffer := make([]byte, 1024)
var total_bytes_read int
for {
len, err := io.ReadAtLeast(res.Body, buffer, 1024)
total_bytes_read += len
log.Println(len, "bytes recevied, total received bytes: ", total_bytes_read)
if err != nil {
if err == io.EOF {
log.Println("EOF: last chunk received")
} else {
log.Println(err)
}
break
}
time.Sleep(1 * time.Second)
}
log.Println("Total bytes received:", total_bytes_read)
err = res.Body.Close()
What I see is:
{"level":"info","msg":"1024 bytes recevied, total received bytes: 1024","time":"2022-06-19T19:47:48-05:00"}
{"level":"info","msg":"1024 bytes recevied, total received bytes: 2048","time":"2022-06-19T19:47:49-05:00"}
{"level":"info","msg":"1024 bytes recevied, total received bytes: 3072","time":"2022-06-19T19:47:50-05:00"}
...
{"level":"info","msg":"1024 bytes recevied, total received bytes: 30720","time":"2022-06-19T19:48:17-05:00"}
{"level":"info","msg":"1024 bytes recevied, total received bytes: 31744","time":"2022-06-19T19:48:18-05:00"}
{"level":"info","msg":"1024 bytes recevied, total received bytes: 32768","time":"2022-06-19T19:48:19-05:00"}
Then it got stuck and waiting for return from the io.Read. Not sure if what I did is correct. Got the same observation when using more popular bufio.Read as well.
Thanks!
-Min