Track transferred bytes/progress of longer PUT request with std.http

Hey,

I want to send bigger chunks of data from a local machine to a storage system using std.http methods. Because the data can be up to some tens or even hundred GiB, it would be nice to track the progress so the user can receive some feedback how long it might take.

But since I’m not very experienced with low-level network stuff, I’m hoping for some tipps.

Whats a good way to accomplish that with std-lib methods? I’ve read through some implementations like std.http.BodyWriter, std.http.Client.Request/Response etc. But since I’m just not very familiar with the underlying concepts, I’m a bit lost. Furthermore, I’m locked in to std.http for now, so custom http libs implemented by other users are no option at the moment.

I’m thankful for any hint; and be it only where to look further. :slightly_smiling_face:

Hello, i might be out of touch, but std had HTTP/1 implementation.
If you are actually transfering in range of 100 GiB, you might want to consider HTTP/2.
At that point, some dependency will be required.

Thanks for the hint. I don’t know the real size ranges now. But they definitely can be in the multi-GiB range. However, the storage system uses HTTP/1.1, which should be fine with std.http if I’m not wrong.

1 Like

If you are sending data using the HTTP client, you need to give it a reader for the body, no? So you implement a custom reader that forwards all vtable functions to the original one, but tracks progress.

1 Like

Ok, that sounds like a good solution, thank you. Does anyone knows of an example/short tutorial how to implement such a custom reader which forwards the vtable functions. While this might be easy/trivial for many programmers, thats what I meant with “concepts” I’m unfamiliar with (while I can use Zig for my own stuff even at work, Im still just a hobby programmer).

Check the implementation of std.Io.net.Stream.Reader (and Writer) It is pretty easy to understand how to implement your own reader or writer from that. You need to implement only one method for each - the one which have no default implementation in the vtable, but since you will probably just be wrapping the Stream variants, you might want to wrap both of the methods Stream implements.