Javascript – How can I access the "request size" before the compression is executed?

I have a global store and a store that works in context:

$ .ajaxSetup ({
beforeSend: Function (jqXHR, Settings) {
myApp.Request.Context = settings.context, jqXHR.url = settings.url;

if (settings.global && (settings.context === "undefined" || settings.context! == "undefined" &&! document.getElementById ("main"). contains (settings.context)))
StartWait ();
},
// Removed code for easier reading ...
xhr: function () {
Let xhr = new window.XMLHttpRequest (), $ context = $ (myApp.Request.Context);

if (myApp.Request.Context) {
xhr.addEventListener ("progress", function (evt) {

console.log ("progress", evt);
console.log ("progress", $ context);
console.log ("lengthComputable", evt.lengthComputable);
console.log ("x-decompressed-content-length"), evt.target.getResponseHeader (x-decompressed-content-length & # 39;);
console.log ("content-length", evt.target.getResponseHeader (& # 39; content-length & # 39;));

leave contentLength;
if (evt.lengthComputable) {
contentLength = evt.total;
} else {
contentLength = evt.target.getResponseHeader (& # 39; content-length & # 39;);
}

let percentComplete = evt.loaded / contentLength * 100;

if (percentComplete === 100) {

console.log ("progress-done", percentComplete);

showInnerLoading (false, $ context);
}
}, not correct);

StartWait (true, myApp.Request.Context);
}

Return xhr;
}

});

Problem: If the request is being compressed by the server, evt.lengthComputable is wrong and evt.total = 0, the contentLength comes with the value of the compressed size, but I need the information of the original size.

Resolved in my view or on the server side by creating an "x-decompressed content – length" header that specifies the original or client-side value with a type of hack.

However, when I try to access the Response OutputStream on the server side of BeginRequest and PreSendRequestContent to get the length, I get an exception.

How do I solve this without having to go to libraries?