Skip to content

Commit 569aed6

Browse files
committed
Do not guess File content-type when it was not present. This change was made for browsers compatibility reasons.
1 parent a444b6c commit 569aed6

File tree

4 files changed

+14
-27
lines changed

4 files changed

+14
-27
lines changed

lib/Encoder.test.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ test("Yields Content-Disposition header for a File", async t => {
125125
test("Yields Content-Type header for a File", async t => {
126126
const fd = new FormData()
127127

128-
fd.set("file", new File(["My hovercraft is full of eels"], "file.txt"))
128+
fd.set("file", new File(["My hovercraft is full of eels"], "file.txt"), {
129+
type: "text/plain"
130+
})
129131

130132
const {value} = await skip(readLine(Readable.from(new Encoder(fd))), 3)
131133

@@ -206,8 +208,14 @@ test("Yields every appended File", async t => {
206208

207209
const fd = new FormData()
208210

209-
fd.append("file", new File(["Some content"], "file.txt"))
210-
fd.append("file", new File(["Some **content**"], "file.md"))
211+
const firstFile = new File(["Some content"], "file.txt", {type: "text/plain"})
212+
const secondFile = new File(["Some **content**"], "file.md", {
213+
type: "text/markdown"
214+
})
215+
216+
fd.append("file", firstFile)
217+
218+
fd.append("file", secondFile)
211219

212220
const iterable = readLine(Readable.from(new Encoder(fd)))
213221

@@ -221,7 +229,7 @@ test("Yields every appended File", async t => {
221229

222230
const {value: firstFileContent} = await skip(iterable, 2)
223231

224-
t.is(firstFileContent, "Some content")
232+
t.is(firstFileContent, await firstFile.text())
225233

226234
const {value: secondFileDisposition} = await skip(iterable, 2)
227235

@@ -233,7 +241,7 @@ test("Yields every appended File", async t => {
233241

234242
const {value: secondFileContent} = await skip(iterable, 2)
235243

236-
t.is(secondFileContent, "Some **content**")
244+
t.is(secondFileContent, await secondFile.text())
237245
})
238246

239247
test("Can be used with ReadableStream", async t => {

lib/Encoder.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import createBoundary from "./util/createBoundary"
2-
import getMime from "./util/getMimeFromFilename"
32
import isFormData from "./util/isFormData"
43
import isFile from "./util/isFile"
54

@@ -98,7 +97,7 @@ export class Encoder {
9897

9998
if (isFile(value)) {
10099
header += `; filename="${value.name}"${this.#CRLF}`
101-
header += `Content-Type: ${value.type || getMime(value.name)}`
100+
header += `Content-Type: ${value.type || "application/octet-stream"}`
102101
}
103102

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

lib/util/getMimeFromFilename.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,5 @@
5858
"ttypescript": "1.5.12",
5959
"typescript": "4.2.4",
6060
"web-streams-polyfill": "3.0.3"
61-
},
62-
"dependencies": {
63-
"mime-types": "2.1.30"
6461
}
6562
}

0 commit comments

Comments
 (0)