This commit is contained in:
みけCAT 2024-05-03 11:01:28 +01:00 committed by GitHub
commit 5a615506c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 7 deletions

View File

@ -32,7 +32,7 @@ class HTTPRequest extends Operation {
].join("\n"); ].join("\n");
this.infoURL = "https://wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields"; this.infoURL = "https://wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields";
this.inputType = "string"; this.inputType = "string";
this.outputType = "string"; this.outputType = "ArrayBuffer";
this.manualBake = true; this.manualBake = true;
this.args = [ this.args = [
{ {
@ -73,12 +73,12 @@ class HTTPRequest extends Operation {
/** /**
* @param {string} input * @param {string} input
* @param {Object[]} args * @param {Object[]} args
* @returns {string} * @returns {ArrayBuffer}
*/ */
run(input, args) { run(input, args) {
const [method, url, headersText, mode, showResponseMetadata] = args; const [method, url, headersText, mode, showResponseMetadata] = args;
if (url.length === 0) return ""; if (url.length === 0) return new Uint8Array(0).buffer;
const headers = new Headers(); const headers = new Headers();
headersText.split(/\r?\n/).forEach(line => { headersText.split(/\r?\n/).forEach(line => {
@ -114,12 +114,17 @@ class HTTPRequest extends Operation {
for (const pair of r.headers.entries()) { for (const pair of r.headers.entries()) {
headers += " " + pair[0] + ": " + pair[1] + "\n"; headers += " " + pair[0] + ": " + pair[1] + "\n";
} }
return r.text().then(b => { return r.arrayBuffer().then(b => {
return "####\n Status: " + r.status + " " + r.statusText + const headerArray = new TextEncoder().encode(
"\n Exposed headers:\n" + headers + "####\n\n" + b; "####\n Status: " + r.status + " " + r.statusText +
"\n Exposed headers:\n" + headers + "####\n\n");
const resultArray = new Uint8Array(headerArray.byteLength + b.byteLength);
resultArray.set(headerArray, 0);
resultArray.set(new Uint8Array(b), headerArray.byteLength);
return resultArray.buffer;
}); });
} }
return r.text(); return r.arrayBuffer();
}) })
.catch(e => { .catch(e => {
throw new OperationError(e.toString() + throw new OperationError(e.toString() +