Skip to content

Instantly share code, notes, and snippets.

@shkhln
Created October 25, 2016 12:53
Show Gist options
  • Save shkhln/b879f3367c3a4e246c5c16ad0b77b1b6 to your computer and use it in GitHub Desktop.
Save shkhln/b879f3367c3a4e246c5c16ad0b77b1b6 to your computer and use it in GitHub Desktop.
diff --git a/framework/src/play-integration-test/src/test/resources/testassets/versioned/sub/fe80fe0ee8f27d99e7028d65d1464d20-foo.txt.md5 b/framework/src/play-integration-test/src/test/resources/testassets/versioned/sub/fe80fe0ee8f27d99e7028d65d1464d20-foo.txt.md5
index 3b9a54f..2c178ff 100644
--- a/framework/src/play-integration-test/src/test/resources/testassets/versioned/sub/fe80fe0ee8f27d99e7028d65d1464d20-foo.txt.md5
+++ b/framework/src/play-integration-test/src/test/resources/testassets/versioned/sub/fe80fe0ee8f27d99e7028d65d1464d20-foo.txt.md5
@@ -1 +1 @@
-fe80fe0ee8f27d99e7028d65d1464d20
\ No newline at end of file
+not used, we can infer the digest from the filename
\ No newline at end of file
diff --git a/framework/src/play/src/main/scala/play/api/controllers/Assets.scala b/framework/src/play/src/main/scala/play/api/controllers/Assets.scala
index e344635..4d18e45 100644
--- a/framework/src/play/src/main/scala/play/api/controllers/Assets.scala
+++ b/framework/src/play/src/main/scala/play/api/controllers/Assets.scala
@@ -177,8 +177,6 @@ package controllers {
digestCache.getOrElse(path, {
val maybeDigestUrl: Option[URL] = resource(path + "." + digestAlgorithm)
val maybeDigest: Option[String] = maybeDigestUrl.map(scala.io.Source.fromURL(_).mkString.trim)
- // if there is no digest file, see if we can infer the digest from the filename
- .orElse(inferDigestFromFilename(path).map(_.digest))
if (enableCaching && maybeDigest.isDefined) digestCache.put(path, maybeDigest)
maybeDigest
})
@@ -224,12 +222,12 @@ package controllers {
for {
url <- resource(name)
} yield {
- val digestUrlOption: Option[String] = digest(name)
- val gzipUrl: Option[URL] = digestUrlOption.flatMap(digestUrl => resource(digestUrl + ".gz")).orElse(resource(name + ".gz"))
- val brotliUrl: Option[URL] = digestUrlOption.flatMap(digestUrl => resource(digestUrl + ".br")).orElse(resource(name + ".br"))
- val lzma2Url: Option[URL] = digestUrlOption.flatMap(digestUrl => resource(digestUrl + ".xz")).orElse(resource(name + ".xz"))
- val bzip2Url: Option[URL] = digestUrlOption.flatMap(digestUrl => resource(digestUrl + ".bz2")).orElse(resource(name + ".bz2"))
- new AssetInfo(name, url, digestUrlOption, gzipUrl, brotliUrl, lzma2Url, bzip2Url, config)
+ val digestOption: Option[String] = inferDigestFromFilename(name).map(_.digest).orElse(digest(name))
+ val gzipUrl: Option[URL] = resource(name + ".gz")
+ val brotliUrl: Option[URL] = resource(name + ".br")
+ val lzma2Url: Option[URL] = resource(name + ".xz")
+ val bzip2Url: Option[URL] = resource(name + ".bz2")
+ new AssetInfo(name, url, digestOption, gzipUrl, brotliUrl, lzma2Url, bzip2Url, config)
}
}
}
@@ -519,10 +517,6 @@ package controllers {
}
}
- private def getUnixPathOfFile(parent: String, filename: String): String = {
- new File(parent, filename).getPath.replace('\\', '/')
- }
-
/**
* Generates an `Action` that serves a versioned static resource.
*/
@@ -530,19 +524,10 @@ package controllers {
val f = new File(file.name)
// We want to detect if it's a fingerprinted asset, because if it's fingerprinted,
// we can aggressively cache it, otherwise we can't.
- val requestedDigest: String = inferDigestFromFilename(f.getName).map(_.digest).getOrElse("")
- if (!requestedDigest.isEmpty) {
- val fileAsRequested: String = getUnixPathOfFile(path, file.name)
+ val isFingerprintedAsset = inferDigestFromFilename(f.getName).isDefined
+ if (isFingerprintedAsset) {
// there is a digest, so we can do aggressive caching.
- // lets see if we can find the file.
- blocking(meta.resource(fileAsRequested)) match {
- case Some(found) =>
- // we have it. serve the file as-is. as it has a digest, cache aggressively
- assetAt(path, file.name, aggressiveCaching = true)
- case _ =>
- // we don't have that file in storage. we should return a 404
- errorHandler.onClientError(request, NOT_FOUND, "Resource not found by Assets controller")
- }
+ assetAt(path, file.name, aggressiveCaching = true)
} else {
// we haven't found any digest information.
assetAt(path, file.name, aggressiveCaching = false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment