Skip to content

Commit

Permalink
Merge pull request #93 from ba-st/use-ZnMultiValueDictionary-in-headers
Browse files Browse the repository at this point in the history
Changed caching directives builder to use the protocol that creates a…
  • Loading branch information
gcotelli authored Jan 2, 2020
2 parents 45bd52b + 53bea2a commit 9678e48
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ PetOrdersRESTfulControllerTest >> getFirstOrderAndWithJsonDo: aBlock [
assert: response contentType asMediaType
equals: resourceController orderVersion1dot0dot0MediaType.
self assertExpiresHeaderFor: response with: 1 minute.
self assertCachingDirectivesFor: response with: 'public, Max-Age=60'.
self assertCachingDirectivesFor: response with: #('public' 'Max-Age=60').
self withJsonFromContentsIn: response do: aBlock
]

Expand Down Expand Up @@ -363,7 +363,7 @@ PetOrdersRESTfulControllerTest >> testGetComments [
assert: response isSuccess;
assert: response contentType equals: ZnMimeType textPlain;
assert: response contents equals: '- Hey!<n>- Mr. DJ' expandMacros.
self assertCachingDirectivesFor: response with: 'S-MaxAge=600, proxy-revalidate'
self assertCachingDirectivesFor: response with: #('S-MaxAge=600' 'proxy-revalidate')
]
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ PetsRESTfulControllerTest >> testGetPetJustCreated [
assert: response contentType asMediaType equals: self defaultPetMediaType;
assert: response entityTag equals: '"c051344b8c92c5ed8a2bd0752070c35ed3de3bab"' asETag.
self assertExpiresHeaderFor: response with: 4 hours.
self assertCachingDirectivesFor: response with: 'public, no-transform, must-revalidate'.
self assertCachingDirectivesFor: response with: #('public' 'no-transform' 'must-revalidate').

self
withJsonFromContentsIn: response
Expand Down Expand Up @@ -375,7 +375,7 @@ PetsRESTfulControllerTest >> testGetPetSummaryJustCreated [
equals: resourceController petSummaryVersion1dot0dot0MediaType;
assert: response entityTag equals: '"1323cdfb8bb0f9011fbd480c5a87c17d05883214"' asETag.
self assertExpiresHeaderFor: response with: 4 hours.
self assertCachingDirectivesFor: response with: 'public, no-transform, must-revalidate'.
self assertCachingDirectivesFor: response with: #('public' 'no-transform' 'must-revalidate').

self
withJsonFromContentsIn: response
Expand Down Expand Up @@ -403,7 +403,7 @@ PetsRESTfulControllerTest >> testGetPets [
assert: response contentType asMediaType
equals: resourceController petSummaryVersion1dot0dot0MediaType.
self assertExpiresHeaderFor: response with: 4 hours.
self assertCachingDirectivesFor: response with: 'public, no-transform, must-revalidate'.
self assertCachingDirectivesFor: response with: #('public' 'no-transform' 'must-revalidate').

self
withJsonFromContentsIn: response
Expand Down Expand Up @@ -435,7 +435,7 @@ PetsRESTfulControllerTest >> testGetPetsNotEmpty [
assert: response contentType asMediaType
equals: resourceController petSummaryVersion1dot0dot0MediaType.
self assertExpiresHeaderFor: response with: 4 hours.
self assertCachingDirectivesFor: response with: 'public, no-transform, must-revalidate'.
self assertCachingDirectivesFor: response with: #('public' 'no-transform' 'must-revalidate').

self
withJsonFromContentsIn: response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ SouthAmericanCurrenciesRESTfulControllerTest >> testGetArgentinePesoBanknotes [
assert: response status equals: 200;
assert: response contentType asMediaType equals: ZnMimeType applicationJson.
self assertExpiresHeaderFor: response with: 365000000 seconds.
self assertCachingDirectivesFor: response with: 'immutable, public, Max-Age=365000000'.
self assertCachingDirectivesFor: response with: #('immutable' 'public' 'Max-Age=365000000').

self
withJsonFromContentsIn: response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ CachingDirectivesBuilderTest >> testBeAvailableFor [
assertThereAre: 3
directivesFrom: builder
whichSetExpiresHeaderTo: 6 hours
andCacheControlHeaderTo: 'public, Max-Age=21600'
andCacheControlHeaderTo: #('public' 'Max-Age=21600')
]

{ #category : #tests }
Expand Down Expand Up @@ -179,7 +179,7 @@ CachingDirectivesBuilderTest >> testDoNotExpire [
assertThereAre: 4
directivesFrom: builder
whichSetExpiresHeaderTo: 365000000 seconds
andCacheControlHeaderTo: 'immutable, public, Max-Age=365000000'
andCacheControlHeaderTo: #('immutable' 'public' 'Max-Age=365000000')
]

{ #category : #tests }
Expand Down Expand Up @@ -238,7 +238,10 @@ CachingDirectivesBuilderTest >> testRequireRevalidation [
builder := CachingDirectivesBuilder new
configureUsing: [ :caching | caching requireRevalidation ];
yourself.
self assertThereAre: 2 directivesFrom: builder whichSetCacheControlHeaderTo: 'no-cache, Max-Age=0'
self
assertThereAre: 2
directivesFrom: builder
whichSetCacheControlHeaderTo: #('no-cache' 'Max-Age=0')
]

{ #category : #tests }
Expand Down
8 changes: 1 addition & 7 deletions source/Stargate-Model/CachingDirectivesBuilder.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@ Class {
{ #category : #private }
CachingDirectivesBuilder >> addCacheControlNamed: aName [

directives
add: [ :response :context |
response headers
at: 'Cache-Control'
put: aName
ifPresentMerge: [ :old :new | '<1s>, <2s>' expandMacrosWith: old with: new ]
]
directives add: [ :response :context | response headers at: 'Cache-Control' add: aName ]
]

{ #category : #private }
Expand Down

0 comments on commit 9678e48

Please sign in to comment.