Hello! I have a question which IDK if it's a missus on my part and there is another way to do it.
I'm writing a client which consumes a MS that returns binary data. I'm using the kithttp.BufferedStream(true) while NewClient to make sure the body is not closed so I can read it when I want and not have it buffered.
This works fine with my implementation of the decode* that I use on the NewClient except if the body is longer than 3966 which then stops reading from the body.
This is my decode*:
func decode(_ context.Context, r *http.Response) (interface{}, error) {
pr, pw := io.Pipe()
go func() {
defer r.Body.Close()
defer pw.Close()
i, err := io.Copy(pw, r.Body)
fmt.Println(i, err)
}()
// IOR is a io.Reader
return response{IOR: pr}, nil
}
The intention is to only read from the r.Body when I need it, that's why I'm using a io.Pipe, and also because I have to r.Body.Close() when it ends (if not, just passing the r.Body to the response.IOR would work, but then the r.Body wold not closed, no?).
This code works for "small" r.Body but when the it's bigger than 3966 the io.Copy stops and the output form the print is 3966 context canceled. So basically the
is called and the body lost.
Maybe I'm overcomplicating it using the io.Pipe but I thought it was the best solution for what I had in mind.
Maybe the defer cancel() should be called once the r.Body.Close() is called as it's I have the BufferedStream option no? IDK if that's even possible haha.
Thanks!
Hello! I have a question which IDK if it's a missus on my part and there is another way to do it.
I'm writing a client which consumes a MS that returns binary data. I'm using the
kithttp.BufferedStream(true)whileNewClientto make sure the body is not closed so I can read it when I want and not have it buffered.This works fine with my implementation of the
decode*that I use on theNewClientexcept if the body is longer than3966which then stops reading from the body.This is my
decode*:The intention is to only read from the
r.Bodywhen I need it, that's why I'm using aio.Pipe, and also because I have tor.Body.Close()when it ends (if not, just passing ther.Bodyto theresponse.IORwould work, but then ther.Bodywold not closed, no?).This code works for "small"
r.Bodybut when the it's bigger than3966theio.Copystops and the output form the print is3966 context canceled. So basically thekit/transport/http/client.go
Line 95 in 4914a69
Maybe I'm overcomplicating it using the
io.Pipebut I thought it was the best solution for what I had in mind.Maybe the
defer cancel()should be called once ther.Body.Close()is called as it's I have theBufferedStreamoption no? IDK if that's even possible haha.Thanks!