Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileMiddleware - Add support for eTag, if-none-match, if-modified-since #53

Merged
merged 5 commits into from
Feb 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
eTag is weak, prefix with W/. Also surround with "
  • Loading branch information
adam-fowler committed Feb 25, 2021
commit a866cd30e7fa77370d4c310b03cc1024fb695958
6 changes: 3 additions & 3 deletions Sources/HummingbirdFoundation/Files/FileMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public struct HBFileMiddleware: HBMiddleware {
headers.add(name: "eTag", value: eTag)

// verify if-none-match. No need to verify if-match as this is used for state changing
// operations
// operations. Also the eTag we generate is considered weak.
let ifNoneMatch = request.headers["if-none-match"]
if ifNoneMatch.count > 0 {
for match in ifNoneMatch {
Expand Down Expand Up @@ -148,7 +148,7 @@ extension HBFileMiddleware {
/// Convert "bytes=value-value" range header into `ClosedRange<Int>`
///
/// Also supports open ended ranges
func getRangeFromHeaderValue(_ header: String) -> ClosedRange<Int>? {
private func getRangeFromHeaderValue(_ header: String) -> ClosedRange<Int>? {
let groups = self.matchRegex(header, expression: "^bytes=([\\d]*)-([\\d]*)$")
guard groups.count == 3 else { return nil }

Expand Down Expand Up @@ -198,7 +198,7 @@ extension HBFileMiddleware {
size = 16
}

return buffer.hexDigest()
return "W/\"\(buffer.hexDigest())\""
}
}

Expand Down