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

Add ETag support for file library #1325

Merged
merged 3 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
private
entityTagFor: aStringOrByteArray
| hash base64 |
hash := GRPlatform current secureHashFor: aStringOrByteArray.
"etags have to be delimited by double quotes"
base64 := GRPlatform current base64Encode: hash asByteArray.
^ String new: base64 size + 2 streamContents: [ :stream |
stream
nextPut: $";
nextPutAll: base64;
nextPut: $"]
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ handle: aRequestContext
contentType: (self mimetypeOf: selector) ] ]
ifFalse: [
aRequestContext respond: [ :response |
response
cacheFor: self cacheDuration;
document: (self documentOf: selector)
mimeType: (self mimetypeOf: selector) ] ]
| document entityTag |
document := self documentOf: selector.
entityTag := self entityTagFor: document.
aRequestContext request ifNoneMatch = entityTag
ifTrue: [ response notModified ]
ifFalse: [
response
cacheFor: self cacheDuration;
entityTag: entityTag;
document: document
mimeType: (self mimetypeOf: selector) ] ] ]
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ handle: aRequestContext
contentType: fileResource mimeType ] ]
ifFalse: [
aRequestContext respond: [ :response |
response
cacheFor: fileResource cacheDuration;
document: fileResource contents value
mimeType: fileResource mimeType ] ]
| document entityTag |
document := fileResource contents value.
entityTag := self entityTagFor: document.
aRequestContext request ifNoneMatch = entityTag
ifTrue: [ response notModified ]
ifFalse: [
response
cacheFor: fileResource cacheDuration;
entityTag: (self entityTagFor: document);
document: document
mimeType: fileResource mimeType ] ] ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
accessing-headers
ifNoneMatch
"The If-None-Match HTTP request header makes the request conditional."

^ self headerAt: 'if-none-match' ifAbsent: [ nil ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
convenience-caching
entityTag: aString
"The ETag (or entity tag) HTTP response header is an identifier for a specific version of a resource."

self headerAt: 'ETag' put: aString
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
status
notModified
"ndicate that there is no need to retransmit the requested resources. It is an implicit redirection to a cached resource."

self status: WAResponse statusNotModified