首页 > 解决方案 > Play Framework 路由在 URI 问题中包含“post”字样

问题描述

我有一个返回文件的播放端点,它看起来像这样:

  def exportContainerPostCalculations(id: Long): Action[AnyContent] = Action.async { implicit request =>
       containerExporter.exportContainerPostCalculationsToCsv(id).map {
          res =>
             Ok.sendFile(new File(res), inline=true).withHeaders(CACHE_CONTROL -> "no-cache", CONTENT_DISPOSITION->s"attachment; filename=${res}", CONTENT_TYPE->"application/x-download");
        }
 }

我有意将 CACHE_CONTROL 设置为“无缓存”,因为我希望在每次服务调用时生成新文件。我最初创建的端点看起来像这样:

GET          /api/export/container/postcalculations/:id       controllers.ExportController.exportContainerPostCalculations(id: Long)

然而,这并没有按预期工作。它总是从缓存返回文件并且使用默认响应头,所以“缓存控制”总是设置为“max-age=3600”。

将端点重命名为:

GET          /api/export/container/finalcalculations/:id       controllers.ExportController.exportContainerPostCalculations(id: Long)

我试图在 Play 文档中找到任何可以解释为什么在路由 URI 中使用“post”会导致这种意外行为的内容,但找不到任何相关内容。我想知道这是否只是 Play 框架中的一个错误,还是我从文档中遗漏了一些东西。

标签: scalarestplayframeworkhttp-headers

解决方案


推荐阅读