File tree 2 files changed +9
-6
lines changed
Sources/HummingbirdFoundation/Files
Tests/HummingbirdFoundationTests
2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -127,12 +127,8 @@ public struct HBFileMiddleware: HBMiddleware {
127
127
headers. add ( name: " eTag " , value: eTag)
128
128
129
129
// content-type
130
- if let extPointIndex = path. lastIndex ( of: " . " ) {
131
- let extIndex = path. index ( after: extPointIndex)
132
- let ext = String ( path. suffix ( from: extIndex) )
133
- if let contentType = HBMediaType . getMediaType ( forExtension: ext) {
134
- headers. add ( name: " content-type " , value: contentType. description)
135
- }
130
+ if let contentType = HBMediaType . getMediaType ( forExtension: fullPath. pathExtension) {
131
+ headers. add ( name: " content-type " , value: contentType. description)
136
132
}
137
133
138
134
headers. replaceOrAdd ( name: " accept-ranges " , value: " bytes " )
Original file line number Diff line number Diff line change @@ -295,9 +295,16 @@ class HummingbirdFilesTests: XCTestCase {
295
295
try app. XCTStart ( )
296
296
defer { app. XCTStop ( ) }
297
297
298
+ try app. XCTExecute ( uri: " /index.html " , method: . GET) { response in
299
+ var body = try XCTUnwrap ( response. body)
300
+ XCTAssertEqual ( body. readString ( length: body. readableBytes) , text)
301
+ XCTAssertEqual ( response. headers. first ( name: " content-type " ) , " text/html " )
302
+ }
303
+
298
304
try app. XCTExecute ( uri: " / " , method: . GET) { response in
299
305
var body = try XCTUnwrap ( response. body)
300
306
XCTAssertEqual ( body. readString ( length: body. readableBytes) , text)
307
+ XCTAssertEqual ( response. headers. first ( name: " content-type " ) , " text/html " )
301
308
}
302
309
}
303
310
You can’t perform that action at this time.
0 commit comments