Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
align = true
align.preset = true
runner.dialect = scala213
assumeStandardLibraryStripMargin = true
danglingParentheses = true
docstrings = JavaDoc
danglingParentheses.preset = true
# Comment processing https://scalameta.org/scalafmt/docs/configuration.html#comment-processing
docstrings {
style = Asterisk
wrap = no
}
maxColumn = 120
project.git = true
rewrite.rules = [ AvoidInfix, ExpandImportSelectors, RedundantParens, SortModifiers, PreferCurlyFors ]
rewrite.sortModifiers.order = [ "private", "protected", "final", "sealed", "abstract", "implicit", "override", "lazy" ]
spaces.inImportCurlyBraces = true # more idiomatic to include whitepsace in import x.{ yyy }
trailingCommas = preserve
version = 2.7.5
version = 3.7.3
12 changes: 6 additions & 6 deletions project/Common.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ object Common extends AutoPlugin {

override def globalSettings =
Seq(
organization := "com.typesafe.play",
organizationName := "The Play Framework Project",
organization := "com.typesafe.play",
organizationName := "The Play Framework Project",
organizationHomepage := Some(url("https://playframework.com/")),
homepage := Some(url(s"https://github.com/playframework/${repoName}")),
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html")),
scalaVersion := Scala212,
crossScalaVersions := ScalaVersions,
homepage := Some(url(s"https://github.com/playframework/${repoName}")),
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html")),
scalaVersion := Scala212,
crossScalaVersions := ScalaVersions,
scalacOptions ++= scalacParameters,
javacOptions ++= javacParameters,
developers += Developer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ object CacheDirectives {
override def toString: String = {
headerNames match {
case Some(names) =>
//This directive uses the quoted-string form of the argument syntax. A
//sender SHOULD NOT generate the token form (even if quoting appears
//not to be needed for single-entry lists).
// This directive uses the quoted-string form of the argument syntax. A
// sender SHOULD NOT generate the token form (even if quoting appears
// not to be needed for single-entry lists).
s"""no-cache="${names.mkString(",")}""""
case None =>
s"no-cache"
Expand Down Expand Up @@ -154,9 +154,9 @@ object CacheDirectives {
override def toString: String = {
headerNames match {
case Some(names) =>
//This directive uses the quoted-string form of the argument syntax. A
//sender SHOULD NOT generate the token form (even if quoting appears
//not to be needed for single-entry lists).
// This directive uses the quoted-string form of the argument syntax. A
// sender SHOULD NOT generate the token form (even if quoting appears
// not to be needed for single-entry lists).
s"""private="${names.mkString(",")}""""
case None =>
"private"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FreshnessCalculator(cache: Cache) {
}
.orElse {
// o If the Expires response header field (Section 5.3) is present, use
//its value minus the value of the Date response header field, or
// its value minus the value of the Date response header field, or
calculateFreshnessFromExpires(request, response)
}
.orElse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class ResponseServingCalculator(cache: Cache) {

explicitValidate
.orElse {
//o the stored response is either:
// o the stored response is either:
//
// * fresh (see Section 4.2), or
val serveFresh: Option[ServeFresh] = isCachedResponseFresh(currentAge)
Expand Down Expand Up @@ -128,9 +128,9 @@ class ResponseServingCalculator(cache: Cache) {
.staleIfError(response.directives)
.map { staleIfError =>
val delta = staleIfError.delta
//Its value indicates the upper limit to staleness; when the cached
//response is more stale than the indicated amount, the cached response
//SHOULD NOT be used to satisfy the request, absent other information.
// Its value indicates the upper limit to staleness; when the cached
// response is more stale than the indicated amount, the cached response
// SHOULD NOT be used to satisfy the request, absent other information.
// https://tools.ietf.org/html/rfc5861#section-4

val serveStale = age.isLessThan(freshnessLifetime.plus(delta))
Expand Down Expand Up @@ -211,9 +211,9 @@ class ResponseServingCalculator(cache: Cache) {
logger.debug(s"noCacheFound: no-cache response directive qualified with ${noCache.headerNames}")
None
case None =>
//The "no-cache" response directive indicates that the response MUST
//NOT be used to satisfy a subsequent request without successful
//validation on the origin server.
// The "no-cache" response directive indicates that the response MUST
// NOT be used to satisfy a subsequent request without successful
// validation on the origin server.
val msg = "Response contains no-args no-cache directive"
Some(Validate(msg))
}
Expand Down Expand Up @@ -305,9 +305,9 @@ class ResponseServingCalculator(cache: Cache) {
logger.trace(s"isStaleResponseAllowed: $currentAge, request = $request, response = $response")
}

//The "max-stale" request directive indicates that the client is
//willing to accept a response that has exceeded its freshness
//lifetime.
// The "max-stale" request directive indicates that the client is
// willing to accept a response that has exceeded its freshness
// lifetime.
val result = CacheDirectives
.maxStale(request.directives)
.flatMap { maxStale =>
Expand Down Expand Up @@ -369,32 +369,32 @@ class ResponseServingCalculator(cache: Cache) {
// cache can satisfy a request with no-store on it and does not
// invalidate it. (Section 5.2.1.5)

//The "must-revalidate" response directive indicates that once it has
//become stale, a cache MUST NOT use the response to satisfy subsequent
//requests without successful validation on the origin server.
// The "must-revalidate" response directive indicates that once it has
// become stale, a cache MUST NOT use the response to satisfy subsequent
// requests without successful validation on the origin server.
// In all circumstances a cache MUST obey the must-revalidate directive;
// in particular, if a cache cannot reach the origin server for any reason,
// it MUST generate a 504 (Gateway Timeout) response.
// https://tools.ietf.org/html/rfc7234#section-5.2.2.1
if (response.directives.contains(MustRevalidate)) {
Some(ValidateOrTimeout("Response is stale, response contains must-revalidate directive"))
} else if (cache.isShared) {
//The "proxy-revalidate" response directive has the same meaning as the
//must-revalidate response directive, except that it does not apply to
//private caches.
// The "proxy-revalidate" response directive has the same meaning as the
// must-revalidate response directive, except that it does not apply to
// private caches.
// https://tools.ietf.org/html/rfc7234#section-5.2.2.7
if (response.directives.contains(ProxyRevalidate)) {
val msg = "Response is stale, response contains proxy-revalidate directive and cache is shared"
Some(ValidateOrTimeout(msg))
} else if (CacheDirectives.sMaxAge(response.directives).isDefined) {
// Note that s-maxage REQUIRES revalidation or timeout, and never serves stale!
//
//Note that cached responses that contain the "must-revalidate" and/or
//"s-maxage" response directives are not allowed to be served stale
//(Section 4.2.4) by shared caches. In particular, a response with
//either "max-age=0, must-revalidate" or "s-maxage=0" cannot be used to
//satisfy a subsequent request without revalidating it on the origin
//server.
// Note that cached responses that contain the "must-revalidate" and/or
// "s-maxage" response directives are not allowed to be served stale
// (Section 4.2.4) by shared caches. In particular, a response with
// either "max-age=0, must-revalidate" or "s-maxage=0" cannot be used to
// satisfy a subsequent request without revalidating it on the origin
// server.
// https://tools.ietf.org/html/rfc7234#section-3.2

// The s-maxage directive also implies the semantics of the proxy-revalidate response directive.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class FreshnessCalculatorSpec extends AnyWordSpec {
"use the Expires headers" in {
val calculator = new FreshnessCalculator(cache)

val request = defaultRequest
val headers = defaultHeaders ++ Map(HeaderName("Expires") -> Seq(HttpDate.format(HttpDate.now.plusSeconds(134))))
val request = defaultRequest
val headers = defaultHeaders ++ Map(HeaderName("Expires") -> Seq(HttpDate.format(HttpDate.now.plusSeconds(134))))
val response: OriginResponse = defaultResponse.copy(headers = headers)

val seconds = calculator.calculateFreshnessLifetime(request, response)
Expand All @@ -77,8 +77,8 @@ class FreshnessCalculatorSpec extends AnyWordSpec {
"use the max-age directive over the expires header" in {
val calculator = new FreshnessCalculator(cache)

//If a response includes a Cache-Control field with the max-age
//directive (Section 5.2.2.8), a recipient MUST ignore the Expires field.
// If a response includes a Cache-Control field with the max-age
// directive (Section 5.2.2.8), a recipient MUST ignore the Expires field.

val request = defaultRequest
val headers = defaultHeaders ++ Map(
Expand All @@ -95,11 +95,11 @@ class FreshnessCalculatorSpec extends AnyWordSpec {
val sharedCache = new StubCache(shared = true)
val calculator = new FreshnessCalculator(sharedCache)

//The "s-maxage" response directive indicates that, in shared caches,
//the maximum age specified by this directive overrides the maximum age
//specified by either the max-age directive or the Expires header
//field. The s-maxage directive also implies the semantics of the
//proxy-revalidate response directive.
// The "s-maxage" response directive indicates that, in shared caches,
// the maximum age specified by this directive overrides the maximum age
// specified by either the max-age directive or the Expires header
// field. The s-maxage directive also implies the semantics of the
// proxy-revalidate response directive.

// Likewise, if a response includes the s-maxage directive
// (Section 5.2.2.9), a shared cache recipient MUST ignore the Expires field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class ResponseCachingCalculatorSpec extends AnyWordSpec {
var called = false
val cacheWithExtensions = new StubCache(shared = false) {
override def isCacheableExtension(extension: CacheDirectives.CacheDirectiveExtension): Boolean = {
called = (extension.name == "public-on-tuesday")
called = extension.name == "public-on-tuesday"
true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ class ResponseSelectionCalculatorSpec extends AnyWordSpec {
}

"return SelectedResponse with the most recent stored response if multiple responses" in {
//If multiple selected responses are available (potentially including
//responses without a Vary header field), the cache will need to choose
//one to use. When a selecting header field has a known mechanism for
//doing so (e.g., qvalues on Accept and similar request header fields),
//that mechanism MAY be used to select preferred responses; of the
//remainder, the most recent response (as determined by the Date header
//field) is used, as per Section 4.
// If multiple selected responses are available (potentially including
// responses without a Vary header field), the cache will need to choose
// one to use. When a selecting header field has a known mechanism for
// doing so (e.g., qvalues on Accept and similar request header fields),
// that mechanism MAY be used to select preferred responses; of the
// remainder, the most recent response (as determined by the Date header
// field) is used, as per Section 4.

val policy = new ResponseSelectionCalculator(cache)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ class ResponseServingCalculatorSpec extends AnyWordSpec {
}

"serviceResponse" when {
//--------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// Request Directives
//--------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

"no-cache request directive" should {
"return Validate" in {
Expand Down Expand Up @@ -258,9 +258,9 @@ class ResponseServingCalculatorSpec extends AnyWordSpec {
}
}

//--------------------------------------------------------------------------------
// --------------------------------------------------------------------------------
// Response Directives
//--------------------------------------------------------------------------------
// --------------------------------------------------------------------------------

"no-cache response directive" should {
"always return Validate, even when fresh" in {
Expand Down Expand Up @@ -288,11 +288,11 @@ class ResponseServingCalculatorSpec extends AnyWordSpec {
}

"return Validate when stale" in {
//A cache MUST NOT generate a stale response if it is prohibited by an
//explicit in-protocol directive (e.g., by a "no-store" or "no-cache"
//cache directive, a "must-revalidate" cache-response-directive, or an
//applicable "s-maxage" or "proxy-revalidate" cache-response-directive;
//see Section 5.2.2).
// A cache MUST NOT generate a stale response if it is prohibited by an
// explicit in-protocol directive (e.g., by a "no-store" or "no-cache"
// cache directive, a "must-revalidate" cache-response-directive, or an
// applicable "s-maxage" or "proxy-revalidate" cache-response-directive;
// see Section 5.2.2).
val policy = new ResponseServingCalculator(privateCache)

val headers = Map(`Cache-Control` -> Seq("max-age=10, no-store"))
Expand Down Expand Up @@ -331,9 +331,9 @@ class ResponseServingCalculatorSpec extends AnyWordSpec {
}

"max-age response directive" should {
//The "max-age" response directive indicates that the response is to be
//considered stale after its age is greater than the specified number
//of seconds.
// The "max-age" response directive indicates that the response is to be
// considered stale after its age is greater than the specified number
// of seconds.

"return ServeFresh when fresh" in {
val policy = new ResponseServingCalculator(privateCache)
Expand Down Expand Up @@ -400,10 +400,10 @@ class ResponseServingCalculatorSpec extends AnyWordSpec {
}

"shared cache" should {
//The "s-maxage" response directive indicates that, in shared caches,
//the maximum age specified by this directive overrides the maximum age
//specified by either the max-age directive or the Expires header
//field.
// The "s-maxage" response directive indicates that, in shared caches,
// the maximum age specified by this directive overrides the maximum age
// specified by either the max-age directive or the Expires header
// field.

"return ServeFresh when fresh, overriding max-age" in {
val policy = new ResponseServingCalculator(sharedCache)
Expand Down Expand Up @@ -435,10 +435,10 @@ class ResponseServingCalculatorSpec extends AnyWordSpec {

// Double check that s-maxage=0 works as defined
"return ValidateOrTimeout when s-maxage=0" in {
//In particular, a response with
//either "max-age=0, must-revalidate" or "s-maxage=0" cannot be used to
//satisfy a subsequent request without revalidating it on the origin
//server.
// In particular, a response with
// either "max-age=0, must-revalidate" or "s-maxage=0" cannot be used to
// satisfy a subsequent request without revalidating it on the origin
// server.
//
// In other words, "s-maxage=0" === "max-age=0, must-revalidate"

Expand All @@ -457,9 +457,9 @@ class ResponseServingCalculatorSpec extends AnyWordSpec {
}
}

//The "proxy-revalidate" response directive has the same meaning as the
//must-revalidate response directive, except that it does not apply to
//private caches.
// The "proxy-revalidate" response directive has the same meaning as the
// must-revalidate response directive, except that it does not apply to
// private caches.
"proxy-revalidate response directive" should {
"return ServeFresh when fresh" in {
val policy = new ResponseServingCalculator(sharedCache)
Expand All @@ -481,9 +481,9 @@ class ResponseServingCalculatorSpec extends AnyWordSpec {
val responseHeaders = Map(`Cache-Control` -> Seq("public, max-age=120, proxy-revalidate"))
val response = defaultResponse.copy(headers = defaultResponse.headers ++ responseHeaders)

//The "must-revalidate" response directive indicates that once it has
//become stale, a cache MUST NOT use the response to satisfy subsequent
//requests without successful validation on the origin server.
// The "must-revalidate" response directive indicates that once it has
// become stale, a cache MUST NOT use the response to satisfy subsequent
// requests without successful validation on the origin server.
val action: ResponseServeAction = policy.serveResponse(request, response, Duration.ofSeconds(300))
action should be(
ValidateOrTimeout(s"Response is stale, response contains proxy-revalidate directive and cache is shared")
Expand All @@ -498,9 +498,9 @@ class ResponseServingCalculatorSpec extends AnyWordSpec {
val responseHeaders = Map(`Cache-Control` -> Seq("public, max-age=120, proxy-revalidate"))
val response = defaultResponse.copy(headers = defaultResponse.headers ++ responseHeaders)

//The "must-revalidate" response directive indicates that once it has
//become stale, a cache MUST NOT use the response to satisfy subsequent
//requests without successful validation on the origin server.
// The "must-revalidate" response directive indicates that once it has
// become stale, a cache MUST NOT use the response to satisfy subsequent
// requests without successful validation on the origin server.
val action: ResponseServeAction = policy.serveResponse(request, response, Duration.ofSeconds(300))
action should be(Validate(s"Response is stale, and stale response is not allowed"))
}
Expand Down