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;
|
||||
}
|
||||
|
||||
function ttx(data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", "/ttx");
|
||||
|
||||
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);
|
||||
async function ttx(data) {
|
||||
const response = await fetch("/ttx", {
|
||||
method: "POST",
|
||||
body: encodeFontData(data),
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(response.statusText);
|
||||
}
|
||||
return response.text();
|
||||
}
|
||||
|
||||
function verifyTtxOutput(output) {
|
||||
|
Loading…
Reference in New Issue
Block a user