We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 718f82c commit b592bf1Copy full SHA for b592bf1
Xcode/Sources/Files.swift
@@ -10,7 +10,14 @@ import Foundation
10
public func shareFile(_ path: String) -> ((HttpRequest) -> HttpResponse) {
11
return { _ in
12
if let file = try? path.openForReading() {
13
- return .raw(200, "OK", [:], { writer in
+ let mimeType = path.mimeType()
14
+ var responseHeader: [String: String] = ["Content-Type": mimeType]
15
+
16
+ if let attr = try? FileManager.default.attributesOfItem(atPath: path),
17
+ let fileSize = attr[FileAttributeKey.size] as? UInt64 {
18
+ responseHeader["Content-Length"] = String(fileSize)
19
+ }
20
+ return .raw(200, "OK", responseHeader, { writer in
21
try? writer.write(file)
22
file.close()
23
})
0 commit comments