diff --git a/packages/server/src/integrations/tests/rest.spec.ts b/packages/server/src/integrations/tests/rest.spec.ts index 7273a2d178..144aefa576 100644 --- a/packages/server/src/integrations/tests/rest.spec.ts +++ b/packages/server/src/integrations/tests/rest.spec.ts @@ -4,7 +4,11 @@ jest.mock("node-fetch", () => { raw: () => { return { "content-type": ["application/json"] } }, - get: () => ["application/json"], + get: (name: string) => { + if (name.toLowerCase() === "content-type") { + return ["application/json"] + } + }, }, json: jest.fn(() => ({ my_next_cursor: 123, @@ -211,7 +215,16 @@ describe("REST Integration", () => { json: json ? async () => json : undefined, text: text ? async () => text : undefined, headers: { - get: (key: any) => (key === "content-length" ? 100 : header), + get: (key: string) => { + switch (key.toLowerCase()) { + case "content-length": + return 100 + case "content-type": + return header + default: + return "" + } + }, raw: () => ({ "content-type": header }), }, } diff --git a/packages/server/src/integrations/utils/restUtils.ts b/packages/server/src/integrations/utils/restUtils.ts index 42c8e939eb..2da9307071 100644 --- a/packages/server/src/integrations/utils/restUtils.ts +++ b/packages/server/src/integrations/utils/restUtils.ts @@ -7,18 +7,20 @@ export function getAttachmentHeaders(headers: Headers) { // the API does not follow the requirements of https://www.ietf.org/rfc/rfc2183.txt // all content-disposition headers should be format disposition-type; parameters // but some APIs do not provide a type, causing the parse below to fail - add one to fix this - const quotesRegex = /"(?:[^"\\]|\\.)*"|;/g - let match: RegExpMatchArray | null = null, - found = false - while ((match = quotesRegex.exec(contentDisposition)) !== null) { - if (match[0] === ";") { - found = true + if (contentDisposition) { + const quotesRegex = /"(?:[^"\\]|\\.)*"|;/g + let match: RegExpMatchArray | null = null, + found = false + while ((match = quotesRegex.exec(contentDisposition)) !== null) { + if (match[0] === ";") { + found = true + } } - } - if (!found) { - return { - contentDisposition: `attachment; ${contentDisposition}`, - contentType, + if (!found) { + return { + contentDisposition: `attachment; ${contentDisposition}`, + contentType, + } } }