Skip to content

Commit

Permalink
Fix: Implemented Conditional GET using etags (#1333)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebKussmaul authored and djones6 committed Dec 13, 2018
1 parent 0bc9aa0 commit 5bc4fd3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions Sources/Kitura/staticFileServer/FileServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,14 @@ extension StaticFileServer {
// Send only headers
_ = response.send(status: .OK)
} else {
// Send the entire file
try response.send(fileName: filePath)
response.statusCode = .OK
if let etag = request.headers["If-None-Match"],
etag == CacheRelatedHeadersSetter.calculateETag(from: fileAttributes) {
response.statusCode = .notModified
} else {
// Send the entire file
try response.send(fileName: filePath)
response.statusCode = .OK
}
}
}
} catch {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Kitura/staticFileServer/StaticFileServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ open class StaticFileServer: RouterMiddleware {
///
/// - Parameter addLastModifiedHeader: an indication whether to set
/// "Last-Modified" header in the response.
/// - Parameter maxAgeCacheControlHeader: a max-age in milliseconds for
/// - Parameter maxAgeCacheControlHeader: a max-age in seconds for
/// "max-age" value in "Cache-Control" header in the response
/// - Parameter generateETag: an indication whether to set "Etag"
/// header in the response.
Expand Down

0 comments on commit 5bc4fd3

Please sign in to comment.