问题
I need to return pdf files with the header
X-Robots-Tag: noindex
https://developers.google.com/webmasters/control-crawl-index/docs/robots_meta_tag?hl=de#robots-meta-tag-verwenden
Is there a way to do this using the standard play Assets Controller? Took a look inside the source code and the only thing that seems to be configurable is:
val configuredCacheControl = config(_.getString("\"assets.cache." + name + "\""))
Thanks
回答1:
I might go with Kris's idea. Something kinda like this should get you part of the way there, basically all I'm doing is leveraging the Play! Controller that serves static resources but adding a header to the result:
object AssetsController extends Controller {
def modifiedAsset(path: String, file: String): Future[Result] = Async.action { implicit request =>
Assets.at(path, file)(request).map { result =>
result.withHeaders(("X-Robots-Tag", "noindex"))
}
}
Then your routes
file would need to be modified from controllers.Assets.at(path="/public", file)
to controllers.AssetsController.modifiedAsset(path="/public", file)
来源:https://stackoverflow.com/questions/36942470/need-to-add-a-a-header-when-returning-an-asset-using-the-play-framework-assets-c