File tree Expand file tree Collapse file tree 3 files changed +45
-247
lines changed
Expand file tree Collapse file tree 3 files changed +45
-247
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -91,10 +91,11 @@ def routes[F[_]: Files: MonadThrow](
9191 object StaticHtmlMiddleware :
9292 def apply (service : HttpRoutes [IO ], injectStyles : Boolean )(logger : Scribe [IO ]): HttpRoutes [IO ] = Kleisli {
9393 (req : Request [IO ]) =>
94- req.headers.get(ci " ETag " ).map(_.toList) match
94+ req.headers.get(ci " If-None-Match " ).map(_.toList) match
9595 case Some (h :: Nil ) if h.value == hashFalse => OptionT .liftF(IO (Response [IO ](Status .NotModified )))
9696 case Some (h :: Nil ) if h.value == hashTrue => OptionT .liftF(IO (Response [IO ](Status .NotModified )))
9797 case _ => service(req).map(userBrowserCacheHeaders(_, zdt, injectStyles))
98+ end match
9899
99100 }
100101
@@ -103,10 +104,26 @@ def routes[F[_]: Files: MonadThrow](
103104 def generatedIndexHtml (injectStyles : Boolean ) =
104105 StaticHtmlMiddleware (
105106 HttpRoutes .of[IO ] {
106- case GET -> Root =>
107- IO (
108- Response [IO ]().withEntity(vanillaTemplate(injectStyles))
109- )
107+ case req @ GET -> Root =>
108+ logger.trace(req.headers.toString) >>
109+ IO (
110+ Response [IO ]()
111+ .withEntity(vanillaTemplate(injectStyles))
112+ .withHeaders(
113+ Header .Raw (ci " Cache-Control " , " no-cache" ),
114+ Header .Raw (
115+ ci " ETag " ,
116+ injectStyles match
117+ case true => hashTrue
118+ case false => hashFalse
119+ ),
120+ Header .Raw (ci " Last-Modified " , formatter.format(zdt)),
121+ Header .Raw (
122+ ci " Expires " ,
123+ httpCacheFormat(ZonedDateTime .ofInstant(Instant .now().plusSeconds(10000000 ), ZoneId .of(" GMT" )))
124+ )
125+ )
126+ )
110127 },
111128 injectStyles
112129 )(logger).combineK(
Original file line number Diff line number Diff line change @@ -199,7 +199,29 @@ class RoutesSuite extends CatsEffectSuite:
199199 IO .unit
200200 }
201201
202- checkResp1 >> checkResp2 >> checkRespSpa
202+ val requestHtml = Request [IO ](uri = uri " / " )
203+ val etag = " 699892091"
204+
205+ val checkRespHtml = client
206+ .run(requestHtml)
207+ .use {
208+ respH =>
209+ assertEquals(respH.status.code, 200 )
210+ assertEquals(respH.headers.get(ci " ETag " ).isDefined, true )
211+ IO .unit
212+ }
213+
214+ val requestHtml2 = Request [IO ](uri = uri " / " ).withHeaders(Header .Raw (ci " If-None-Match " , etag))
215+
216+ val checkRespHtml2 = client
217+ .run(requestHtml2)
218+ .use {
219+ respH =>
220+ assertEquals(respH.status.code, 304 )
221+ IO .unit
222+ }
223+
224+ checkResp1 >> checkResp2 >> checkRespSpa >> checkRespHtml >> checkRespHtml2
203225
204226 }
205227 }
You can’t perform that action at this time.
0 commit comments