Skip to content

Commit c62789b

Browse files
committed
Update makeContentType function for multiplatform support
1 parent c7ee610 commit c62789b

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

FlyingFox/Sources/Handlers/FileHTTPHandler.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,24 @@ public struct FileHTTPHandler: HTTPHandler {
5353
static func makeContentType(for filename: String) -> String {
5454
let pathExtension = (filename.lowercased() as NSString).pathExtension
5555
#if canImport(UniformTypeIdentifiers)
56-
switch pathExtension {
57-
case "wasm":
58-
return "application/wasm"
59-
case "properties":
60-
return "text/plain"
61-
default:
62-
return UTType(filenameExtension: pathExtension)?.preferredMIMEType ?? "application/octet-stream"
56+
if #available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *) {
57+
switch pathExtension {
58+
case "wasm":
59+
return "application/wasm"
60+
case "properties":
61+
return "text/plain"
62+
default:
63+
return UTType(filenameExtension: pathExtension)?.preferredMIMEType ?? "application/octet-stream"
64+
}
65+
} else {
66+
return legacyMakeContentType(for: pathExtension)
6367
}
6468
#else
69+
return legacyMakeContentType(for: pathExtension)
70+
#endif
71+
}
72+
73+
private static func legacyMakeContentType(for pathExtension: String) -> String {
6574
switch pathExtension {
6675
case "json":
6776
return "application/json"
@@ -100,7 +109,6 @@ public struct FileHTTPHandler: HTTPHandler {
100109
default:
101110
return "application/octet-stream"
102111
}
103-
#endif
104112
}
105113

106114
public func handleRequest(_ request: HTTPRequest) async throws -> HTTPResponse {

0 commit comments

Comments
 (0)