diff options
author | Sergey Nastich <nastich@users.noreply.github.com> | 2018-09-10 19:05:40 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-10 19:05:40 -0400 |
commit | b3b426046a199307ce80d01b604115890724cb22 (patch) | |
tree | abe9a73aeda665e0138a9fe01924768de7129c60 /src/main/scala/xyz/driver/core/rest | |
parent | f07bee564b11ee76fd065ec849a888bcf4e74e85 (diff) | |
download | driver-core-b3b426046a199307ce80d01b604115890724cb22.tar.gz driver-core-b3b426046a199307ce80d01b604115890724cb22.tar.bz2 driver-core-b3b426046a199307ce80d01b604115890724cb22.zip |
Add `Cache-Control: no-cache` to all responses of DriverRoutes. (#190)
This change is intended to battle IE (even IE 11) caching all
GET responses (and not making any new ones) that don't list those headers
Diffstat (limited to 'src/main/scala/xyz/driver/core/rest')
-rw-r--r-- | src/main/scala/xyz/driver/core/rest/DriverRoute.scala | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/main/scala/xyz/driver/core/rest/DriverRoute.scala b/src/main/scala/xyz/driver/core/rest/DriverRoute.scala index 288245a..911e306 100644 --- a/src/main/scala/xyz/driver/core/rest/DriverRoute.scala +++ b/src/main/scala/xyz/driver/core/rest/DriverRoute.scala @@ -2,8 +2,9 @@ package xyz.driver.core.rest import java.sql.SQLException -import akka.http.scaladsl.model.{StatusCodes, _} +import akka.http.scaladsl.model.headers.CacheDirectives.`no-cache` import akka.http.scaladsl.model.headers._ +import akka.http.scaladsl.model.{StatusCodes, _} import akka.http.scaladsl.server.Directives._ import akka.http.scaladsl.server._ import com.typesafe.scalalogging.Logger @@ -32,11 +33,7 @@ trait DriverRoute { val tracingHeader = RawHeader(ContextHeaders.TrackingIdHeader, trackingId) MDC.put("trackingId", trackingId) - // This header will eliminate the risk of LB trying to reuse a connection - // that already timed out on the server side by completely rejecting keep-alive - val rejectKeepAlive = Connection("close") - - respondWithHeaders(tracingHeader, rejectKeepAlive) + respondWithHeaders(tracingHeader +: DriverRoute.DefaultHeaders: _*) } } @@ -112,3 +109,14 @@ trait DriverRoute { } } + +object DriverRoute { + val DefaultHeaders: List[HttpHeader] = List( + // This header will eliminate the risk of envoy trying to reuse a connection + // that already timed out on the server side by completely rejecting keep-alive + Connection("close"), + // These 2 headers are the simplest way to prevent IE from caching GET requests + RawHeader("Pragma", "no-cache"), + `Cache-Control`(List(`no-cache`(Nil))) + ) +} |