diff --git a/repository/Seaside-Core.package/WAAbstractFileLibrary.class/instance/entityTagFor..st b/repository/Seaside-Core.package/WAAbstractFileLibrary.class/instance/entityTagFor..st new file mode 100644 index 000000000..6e6237034 --- /dev/null +++ b/repository/Seaside-Core.package/WAAbstractFileLibrary.class/instance/entityTagFor..st @@ -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: $"] \ No newline at end of file diff --git a/repository/Seaside-Core.package/WAFileLibrary.class/instance/handle..st b/repository/Seaside-Core.package/WAFileLibrary.class/instance/handle..st index 5871d99fc..d64b746fc 100644 --- a/repository/Seaside-Core.package/WAFileLibrary.class/instance/handle..st +++ b/repository/Seaside-Core.package/WAFileLibrary.class/instance/handle..st @@ -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) ] ] \ No newline at end of file + | 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) ] ] ] \ No newline at end of file diff --git a/repository/Seaside-Core.package/WAFileMetadataLibrary.class/instance/handle..st b/repository/Seaside-Core.package/WAFileMetadataLibrary.class/instance/handle..st index 71ee672b6..cbf883920 100644 --- a/repository/Seaside-Core.package/WAFileMetadataLibrary.class/instance/handle..st +++ b/repository/Seaside-Core.package/WAFileMetadataLibrary.class/instance/handle..st @@ -22,7 +22,14 @@ handle: aRequestContext contentType: fileResource mimeType ] ] ifFalse: [ aRequestContext respond: [ :response | - response - cacheFor: fileResource cacheDuration; - document: fileResource contents value - mimeType: fileResource mimeType ] ] \ No newline at end of file + | 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 ] ] ] \ No newline at end of file diff --git a/repository/Seaside-Core.package/WARequest.class/instance/ifNoneMatch.st b/repository/Seaside-Core.package/WARequest.class/instance/ifNoneMatch.st new file mode 100644 index 000000000..9ae4e77ec --- /dev/null +++ b/repository/Seaside-Core.package/WARequest.class/instance/ifNoneMatch.st @@ -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 ] \ No newline at end of file diff --git a/repository/Seaside-Core.package/WAResponse.class/instance/entityTag..st b/repository/Seaside-Core.package/WAResponse.class/instance/entityTag..st new file mode 100644 index 000000000..40408d3db --- /dev/null +++ b/repository/Seaside-Core.package/WAResponse.class/instance/entityTag..st @@ -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 \ No newline at end of file diff --git a/repository/Seaside-Core.package/WAResponse.class/instance/notModified.st b/repository/Seaside-Core.package/WAResponse.class/instance/notModified.st new file mode 100644 index 000000000..c8193bb14 --- /dev/null +++ b/repository/Seaside-Core.package/WAResponse.class/instance/notModified.st @@ -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 \ No newline at end of file