Ajax: ¿Cómo saber si la implementación de un script de usuario no establece el encabezado Origin?

Algunas implementaciones de script de usuario (como Google Chrome) permiten solicitudes cruzadas directas de AJAX, pero otras no, y usan restricciones de la Política del mismo origen. Aquí hay una parte del código:

/*
 * Get the size of the file.
 * @Button the current button for downloading the video.
 * @Url the http url of the video.
 */
function SetFileSize(Button, Url) {
    var ajax = new XMLHttpRequest();
    ajax.onloadend = function () {
        GetResolution(Button, Url, ' - ' + (parseInt(this.getResponseHeader("Content-Length")) / 1048576).toFixed(3) + ' Mo')
    }
    ajax.open('HEAD', Url, true); // <-- HEAD allow to get only the data of the headers.
    ajax.send(null);
}

/*
 * Retrieve width and height from an MPEG-4 file.
 * Width and height are stored as float values, where width come next to height inside binary data.
 * There is no fixed place in the file. The method is to get them at 10 bytes before "mdia".
 */
function GetResolution(Button, Url, FileSize) {
    var ajax = new XMLHttpRequest();
    ajax.onloadend = function () {
        var metadata = new DataView(this.response);
        for (i = 0;(i < metadata.byteLength) && (metadata.getUint32(i) != 0x6D646961); i += 32) {} // 0x6D646961="mdia"
        button.setAttribute('title', metadata.getUint32(i - 14) + 'x' + metadata.getUint32(i - 10) + FileSize);
    }
    ajax.responseType = 'arraybuffer'; // We want to handle binary data.
    ajax.open('GET', Url, true); // <-- the 'false' have been deprecated.
    ajax.setRequestHeader('Range', 'bytes=181-300'); // Proceed with a partial download.
    ajax.send(null);
}

El resultado es el servidor.(https://cors-anywhere.herokuapp.com/) envía un error 400 diciéndole alOriginFalta el encabezado. Los navegadores no permiten configurar elOriginencabezado por lo que un truco rápido y sucio sería establecer la costumbrex-requested-with. Si un navegador antiguo configura elOriginencabezado correctamente, esto hace un duplicado dex-requested-with. Aquí sería el código:

ajax.setRequestHeader('x-requested-with', document.domain); // chrome doesn't support setting the 'Origin' header automatically.

No puedo usarprueba de declaraciones dado que las solicitudes AJAX sincrónicas quedaron en desuso ni puedo configurar el encabezado Origin. Entonces, ¿cómo puedo saber si el navegador no establece un encabezado particular?

Respuestas a la pregunta(0)

Su respuesta a la pregunta