1515 */
1616package io.github.nstdio.http.ext
1717
18+ import io.github.nstdio.http.ext.Headers.HEADER_WARNING
19+ import io.github.nstdio.http.ext.Helpers.responseInfo
20+ import io.github.nstdio.http.ext.Helpers.responseInfo0
1821import io.kotest.matchers.booleans.shouldBeFalse
1922import io.kotest.matchers.booleans.shouldBeTrue
23+ import io.kotest.matchers.collections.shouldContainOnly
2024import io.kotest.matchers.longs.shouldBeNegative
25+ import io.kotest.matchers.should
2126import org.junit.jupiter.api.Assertions.assertFalse
2227import org.junit.jupiter.api.Disabled
2328import org.junit.jupiter.api.Nested
@@ -47,7 +52,7 @@ internal class CacheEntryMetadataTest {
4752 " Accept-Language" , " en-EN"
4853 )
4954 .build()
50- val m = CacheEntryMetadata (0 , 0 , Helpers . responseInfo(headers), r, Clock .systemDefaultZone())
55+ val m = CacheEntryMetadata (0 , 0 , responseInfo(headers), r, Clock .systemDefaultZone())
5156
5257 // when
5358 val actual = m.varyHeaders()
@@ -59,6 +64,34 @@ internal class CacheEntryMetadataTest {
5964 .hasHeaderWithValues(" User-Agent" , " Java/11" )
6065 }
6166
67+ @Test
68+ fun `Should remove warning header from response` () {
69+ // given
70+ val request = HttpRequest .newBuilder(URI .create(" https://example.com" )).build()
71+ val responseInfo = responseInfo0(
72+ mapOf (
73+ HEADER_WARNING to listOf (
74+ " 112 - \" cache down\" \" Wed, 21 Oct 2015 07:28:00 GMT\" " ,
75+ " 110 anderson/1.3.37 \" Response is stale\" " ,
76+ " 299 - \" Deprecated\" "
77+ )
78+ )
79+ )
80+ val metadata = CacheEntryMetadata (0 , 0 , responseInfo, request, Clock .systemDefaultZone())
81+ val responseHeaders = HttpHeadersBuilder ()
82+ .add(" X-A" , " B" )
83+ .build()
84+
85+ // when
86+ metadata.update(responseHeaders, 0 , 0 )
87+
88+ // then
89+ metadata.response().headers().should {
90+ it.allValues(HEADER_WARNING ).shouldContainOnly(" 299 - \" Deprecated\" " )
91+ it.allValues(" X-A" ).shouldContainOnly(" B" )
92+ }
93+ }
94+
6295 @Test
6396 fun shouldGenerateHeuristicExpirationWarning () {
6497 // given
@@ -68,7 +101,7 @@ internal class CacheEntryMetadataTest {
68101 // Creating Last-Modified just about to exceed 24 hour limit
69102 val lastModified = baseInstant.minus(241 , ChronoUnit .HOURS )
70103 val expectedExpirationTime = baseInstant.plus(2 , ChronoUnit .DAYS )
71- val info = Helpers . responseInfo(
104+ val info = responseInfo(
72105 mutableMapOf (
73106 " Last-Modified" to Headers .toRFC1123(lastModified),
74107 " Date" to Headers .toRFC1123(Instant .ofEpochSecond(0 ))
@@ -110,7 +143,7 @@ internal class CacheEntryMetadataTest {
110143 val baseClock = Clock .systemUTC()
111144 val dateHeader = baseClock.instant()
112145 val clock = FixedRateTickClock .of(baseClock, Duration .ofSeconds(1 ))
113- val info = Helpers . responseInfo(
146+ val info = responseInfo(
114147 mutableMapOf (
115148 " Cache-Control" to " max-age=1,must-revalidate" ,
116149 " Date" to Headers .toRFC1123(dateHeader)
@@ -141,7 +174,7 @@ internal class CacheEntryMetadataTest {
141174 val responseTimeMs: Long = 350
142175 val serverDate = responseTimeMs - 50
143176 val clock = Clock .fixed(Instant .ofEpochMilli(responseTimeMs + 5 ), ZoneId .systemDefault())
144- val info = Helpers . responseInfo(
177+ val info = responseInfo(
145178 mutableMapOf (
146179 " Cache-Control" to " max-age=1" ,
147180 " Date" to Headers .toRFC1123(Instant .ofEpochMilli(serverDate))
0 commit comments