Skip to content

Commit

Permalink
use streaming for v1 and v2, and fix the filename extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Sep 5, 2023
1 parent 32a8aff commit 5a9a254
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
3 changes: 2 additions & 1 deletion packages/core/src/NodeExecuteFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1011,9 +1011,10 @@ async function prepareBinaryData(
if (binaryData instanceof IncomingMessage) {
if (!filePath) {
try {
const { responseUrl } = binaryData;
filePath =
binaryData.contentDisposition?.filename ??
new URL(binaryData.responseUrl).pathname.slice(1);
((responseUrl && new URL(responseUrl).pathname) ?? binaryData.req?.path)?.slice(1);
} catch {}
}
if (!mimeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ export class HttpRequestV1 implements INodeType {
oAuth2Api = await this.getCredentials('oAuth2Api');
} catch {}

let requestOptions: OptionsWithUri;
let requestOptions: OptionsWithUri & { useStream?: boolean };
let setUiParameter: IDataObject;

const uiParameters: IDataObject = {
Expand Down Expand Up @@ -875,6 +875,7 @@ export class HttpRequestV1 implements INodeType {

if (responseFormat === 'file') {
requestOptions.encoding = null;
requestOptions.useStream = true;

if (options.bodyContentType !== 'raw') {
requestOptions.body = JSON.stringify(requestOptions.body);
Expand All @@ -887,6 +888,7 @@ export class HttpRequestV1 implements INodeType {
}
} else if (options.bodyContentType === 'raw') {
requestOptions.json = false;
requestOptions.useStream = true;
} else {
requestOptions.json = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ export class HttpRequestV2 implements INodeType {
} catch {}
}

let requestOptions: OptionsWithUri;
let requestOptions: OptionsWithUri & { useStream?: boolean };
let setUiParameter: IDataObject;

const uiParameters: IDataObject = {
Expand Down Expand Up @@ -915,6 +915,7 @@ export class HttpRequestV2 implements INodeType {

if (responseFormat === 'file') {
requestOptions.encoding = null;
requestOptions.useStream = true;

if (options.bodyContentType !== 'raw') {
requestOptions.body = JSON.stringify(requestOptions.body);
Expand All @@ -927,6 +928,7 @@ export class HttpRequestV2 implements INodeType {
}
} else if (options.bodyContentType === 'raw') {
requestOptions.json = false;
requestOptions.useStream = true;
} else {
requestOptions.json = true;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/workflow/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ declare module 'http' {
rawBody: Buffer;
readRawBody(): Promise<void>;
_body: boolean;

// This gets added by the `follow-redirects` package
responseUrl: string;
responseUrl?: string;

// This is added to response objects for all outgoing requests
req?: ClientRequest;
}
}

0 comments on commit 5a9a254

Please sign in to comment.