[GH-ISSUE #872] [Scripting] Import a huge file in a script takes a long time to response #867

Open
opened 2026-03-03 19:22:34 +03:00 by kerem · 1 comment
Owner

Originally created by @NghiaTranUIT on GitHub (Apr 29, 2021).
Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/872

Originally assigned to: @NghiaTranUIT on GitHub.

Description

If we import the file in the a Scripting, by using the following JS code:

const file = require("@users/myfile.json");

If the file is a large file, the script might run slowly.
The reason is that Proxyman would perform two tasks:

  1. Read a local file in Swift and parse it to JS Object. Then passing to JS Environment
  2. Getting the JS Object again and parse it to Swift Object

As a result, it might take more than 20 seconds to respond if a file is ~2Mb.

We should fix it.

Acceptance Criteria

  • Introduce request.bodyFilePath = "~/Desktop/file.json", so Proxyman could get the binary directly without parsing twice
Originally created by @NghiaTranUIT on GitHub (Apr 29, 2021). Original GitHub issue: https://github.com/ProxymanApp/Proxyman/issues/872 Originally assigned to: @NghiaTranUIT on GitHub. ### Description If we [import the file](https://docs.proxyman.io/scripting/snippet-code#import-files) in the a Scripting, by using the following JS code: ```js const file = require("@users/myfile.json"); ``` If the file is a large file, the script might run slowly. The reason is that Proxyman would perform two tasks: 1. Read a local file in Swift and parse it to JS Object. Then passing to JS Environment 2. Getting the JS Object again and parse it to Swift Object As a result, it might take more than 20 seconds to respond if a file is ~2Mb. We should fix it. ### Acceptance Criteria - Introduce `request.bodyFilePath = "~/Desktop/file.json"`, so Proxyman could get the binary directly without parsing twice
Author
Owner

@NghiaTranUIT commented on GitHub (Apr 29, 2021):

Beta: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.24.0_Better_File_Import_Scripting.dmg

// For request
request.bodyFilePath = "~/Desktop/image.png";

// For response
response.bodyFilePath = "~/Desktop/image.png";

Example:

function onResponse(context, url, request, response) {
 
  response.headers["Content-Type"] = "image/png";
  response.bodyFilePath = "~/Desktop/image.png";
 
  // Done
  return response;
}
<!-- gh-comment-id:829269622 --> @NghiaTranUIT commented on GitHub (Apr 29, 2021): Beta: https://proxyman.s3.us-east-2.amazonaws.com/beta/Proxyman_2.24.0_Better_File_Import_Scripting.dmg ```js // For request request.bodyFilePath = "~/Desktop/image.png"; // For response response.bodyFilePath = "~/Desktop/image.png"; ``` Example: ```js function onResponse(context, url, request, response) { response.headers["Content-Type"] = "image/png"; response.bodyFilePath = "~/Desktop/image.png"; // Done return response; } ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Proxyman#867
No description provided.