From 53bea2a616d2e774da55254edaf2a6610fc55cae Mon Sep 17 00:00:00 2001 From: Maximiliano Tabacman Date: Mon, 30 Dec 2019 21:41:27 -0300 Subject: [PATCH] Changed caching directives builder to use the protocol that creates a ZnMultiValueDictionary. --- .../PetOrdersRESTfulControllerTest.class.st | 4 ++-- .../PetsRESTfulControllerTest.class.st | 8 ++++---- ...SouthAmericanCurrenciesRESTfulControllerTest.class.st | 2 +- .../CachingDirectivesBuilderTest.class.st | 9 ++++++--- source/Stargate-Model/CachingDirectivesBuilder.class.st | 8 +------- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/source/Stargate-Examples-Tests/PetOrdersRESTfulControllerTest.class.st b/source/Stargate-Examples-Tests/PetOrdersRESTfulControllerTest.class.st index 33d06e0..3e6652b 100644 --- a/source/Stargate-Examples-Tests/PetOrdersRESTfulControllerTest.class.st +++ b/source/Stargate-Examples-Tests/PetOrdersRESTfulControllerTest.class.st @@ -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 ] @@ -363,7 +363,7 @@ PetOrdersRESTfulControllerTest >> testGetComments [ assert: response isSuccess; assert: response contentType equals: ZnMimeType textPlain; assert: response contents equals: '- Hey!- Mr. DJ' expandMacros. - self assertCachingDirectivesFor: response with: 'S-MaxAge=600, proxy-revalidate' + self assertCachingDirectivesFor: response with: #('S-MaxAge=600' 'proxy-revalidate') ] ] diff --git a/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st b/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st index a4dfc80..c3aa4e2 100644 --- a/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st +++ b/source/Stargate-Examples-Tests/PetsRESTfulControllerTest.class.st @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st b/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st index 571922c..63ea9c4 100644 --- a/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st +++ b/source/Stargate-Examples-Tests/SouthAmericanCurrenciesRESTfulControllerTest.class.st @@ -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 diff --git a/source/Stargate-Model-Tests/CachingDirectivesBuilderTest.class.st b/source/Stargate-Model-Tests/CachingDirectivesBuilderTest.class.st index 598aec9..f08e33a 100644 --- a/source/Stargate-Model-Tests/CachingDirectivesBuilderTest.class.st +++ b/source/Stargate-Model-Tests/CachingDirectivesBuilderTest.class.st @@ -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 } @@ -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 } @@ -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 } diff --git a/source/Stargate-Model/CachingDirectivesBuilder.class.st b/source/Stargate-Model/CachingDirectivesBuilder.class.st index 3c12671..19e0e5f 100644 --- a/source/Stargate-Model/CachingDirectivesBuilder.class.st +++ b/source/Stargate-Model/CachingDirectivesBuilder.class.st @@ -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 }