Skip to content

Commit 724c52b

Browse files
committed
Refactor getFieldHeader method.
1 parent 2907bfd commit 724c52b

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

src/FormDataEncoder.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,11 @@ export class FormDataEncoder {
214214
header += `Content-Type: ${value.type || "application/octet-stream"}`
215215
}
216216

217-
const size = isFile(value) ? value.size : value.byteLength
218-
if (
219-
this.#options.enableAdditionalHeaders === true
220-
&& size != null
221-
&& !isNaN(size)
222-
) {
223-
header += `${this.#CRLF}Content-Length: ${
224-
isFile(value) ? value.size : value.byteLength
225-
}`
217+
if (this.#options.enableAdditionalHeaders === true) {
218+
const size = isFile(value) ? value.size : value.byteLength
219+
if (size != null && !isNaN(size)) {
220+
header += `${this.#CRLF}Content-Length: ${size}`
221+
}
226222
}
227223

228224
return this.#encoder.encode(`${header}${this.#CRLF.repeat(2)}`)

0 commit comments

Comments
 (0)