The body is just an io.Reader. You just need to write one that materializes and streams the data you want instead of using a buffer with all of it. The entire design is to allow things like what you want to do. :)
-Bruno On Mon, Mar 6, 2023 at 10:08 AM 'Jim Smart' via golang-nuts < golang-nuts@googlegroups.com> wrote: > Hi all, > > I'm looking for an HTTP client that allows my code to write the body > content down the pipe while doing a POST. > > The use case here is that I'm wishing to send very large UPDATE/INSERT > queries/commands to an HTTP endpoint, and the body content of those > queries/commands is actually generated from a database. So it would be > better, memory- and performance- wise, if I could write that straight down > the pipe during the request, as opposed to manifesting the whole of the > query/command into a buffer before doing the POST. > > Is this possible at all with the stdlib http.Client? Perhaps with an > io.Pipe as the request body? > > I did look at the code for http.Client a little, but there's a lot of it, > and it's not the simplest of code to follow. I do have a base understanding > of the HTTP 1.1 protocol, but there's a lot more to http.Client than just > that, of course. > > I've also tried looking for existing examples showing similar > functionality, but did not seem to find anything. Which is partly what > makes me wonder if perhaps the stdlib http.Client cannot operate like this. > > If I can't do this with the stdlib http.Client, and I have to roll-my-own > client of sorts, are there any parts of the existing http package that I > should be making use of? > > Any tips / pointers / info greatly appreciated. > > Thanks, > /Jim > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/545d0597-66a0-4412-8ca7-3d447f88ccafn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/545d0597-66a0-4412-8ca7-3d447f88ccafn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAEd86TywTP1FMMdcBLH-CN-Nq0uCErM1r2yUZ211YC-%3D4v5mFA%40mail.gmail.com.