Convert the font-test ttx
helper function to use the Fetch API
By replacing `XMLHttpRequest` with a `fetch` call, the helper function can be modernized to use async/await instead. Note that the headers doesn't seem necessary to set now, since: - The Fetch API provides a method for accessing the response as *text*, which renders the "Content-type" header unnecessary. - According to https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name, the "Content-length" header isn't necessary.
This commit is contained in:
parent
3d55b2b10e
commit
7b8d2495ca
@ -65,26 +65,16 @@ function encodeFontData(data) {
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ttx(data) {
|
async function ttx(data) {
|
||||||
return new Promise((resolve, reject) => {
|
const response = await fetch("/ttx", {
|
||||||
const xhr = new XMLHttpRequest();
|
method: "POST",
|
||||||
xhr.open("POST", "/ttx");
|
body: encodeFontData(data),
|
||||||
|
|
||||||
const encodedData = encodeFontData(data);
|
|
||||||
xhr.setRequestHeader("Content-type", "text/plain");
|
|
||||||
xhr.setRequestHeader("Content-length", encodedData.length);
|
|
||||||
|
|
||||||
xhr.onreadystatechange = function getPdfOnreadystatechange(e) {
|
|
||||||
if (xhr.readyState === 4) {
|
|
||||||
if (xhr.status === 200) {
|
|
||||||
resolve(xhr.responseText);
|
|
||||||
} else {
|
|
||||||
reject(new Error(xhr.statusText));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
xhr.send(encodedData);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error(response.statusText);
|
||||||
|
}
|
||||||
|
return response.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
function verifyTtxOutput(output) {
|
function verifyTtxOutput(output) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user