fix(common): handle File objects in HAR postData text resolution (#5917)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> Co-authored-by: James George <25279263+jamesgeorge007@users.noreply.github.com>
This commit is contained in:
parent
744f434698
commit
b728f5da24
1 changed files with 23 additions and 0 deletions
|
|
@ -114,6 +114,29 @@ const buildHarPostData = (req: HoppRESTRequest): Har.PostData | undefined => {
|
|||
}
|
||||
}
|
||||
|
||||
// application/octet-stream bodies are File | null; emit @filename for file uploads
|
||||
if (req.body.contentType === "application/octet-stream") {
|
||||
const file = req.body.body
|
||||
|
||||
if (!file) {
|
||||
return {
|
||||
mimeType: req.body.contentType,
|
||||
text: "",
|
||||
}
|
||||
}
|
||||
|
||||
// `path` exists in some desktop runtimes; `name` is the standard File field.
|
||||
const filename =
|
||||
"path" in file && typeof file.path === "string" && file.path
|
||||
? file.path
|
||||
: file.name || "<binary-file>"
|
||||
|
||||
return {
|
||||
mimeType: req.body.contentType,
|
||||
text: `@${filename}`,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
mimeType: req.body.contentType, // Let's assume by default content type is JSON
|
||||
text: (req.body.body as string) ?? "",
|
||||
|
|
|
|||
Loading…
Reference in a new issue