How to know how much of an aborted POST request was sent?

Viewed 33

I want to send a POST request with a huge body to a server, then abort it after a specified period so I could measure the uplink bandwidth. I know that cloudflare's speedtest website accepts such requests. The api looks like this: to send a 1MB file one can simply use this snippet.

let size = 1 * 1e6; // 1MB
let url = `https://speed.cloudflare.com/__up`;
let req =  await fetch(`${url}`, {...{
  method: 'POST',
  body: '0'.repeat(size),
  headers: { 'content-length': size }
}});
let res = await req.text();
console.log(res);

Copy pasting the snippet above in a chrome console sends out a successful 1MB request for me.

What I'm trying to do is to abort this request using the Abort Controller API, then have some form of measurement over how much of the body of the request was sent to the server.

For download I can do that as I use the ReadableStream on the download request so I know how much of the file was downloaded before I cancelled the download.

Is this possible?

0 Answers
Related