I'm building a decentralized application (I don't control the servers, only the client), and want to add some sanity checks and preventative measures to stop bad people from doing malicious things. This involves (among many, many other things), preventing DoS attempts on the client by the use of arbitrary payload data being sent from the servers.
The question is this: How can the client limit the maximum size of data received from a server over JQuery AJAX? If I'm expecting to fetch a few bytes of JSON, and am instead greeted by a 30MB video file when I make the AJAX request, how can I stop the request and throw an error after I've received the first 16 KB?
While I recognize that the nature of my undertaking is unique, any feedback is wwlcome.