From c201b3ecf5802ab478cd171e387bc67915a491b5 Mon Sep 17 00:00:00 2001 From: Niklas Fiekas Date: Thu, 19 Dec 2019 15:32:41 +0100 Subject: [PATCH] set coop/coep headers for multi-threaded stockfish (closes #5784) --- app/controllers/LilaController.scala | 7 ++++++- app/controllers/Puzzle.scala | 12 +++++++----- app/controllers/Relay.scala | 2 +- app/controllers/Study.scala | 2 +- app/controllers/UserAnalysis.scala | 2 +- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/app/controllers/LilaController.scala b/app/controllers/LilaController.scala index b2e660a33eed5..f9656ca9178f5 100644 --- a/app/controllers/LilaController.scala +++ b/app/controllers/LilaController.scala @@ -43,7 +43,7 @@ abstract private[controllers] class LilaController(val env: Env) protected val keyPages = new KeyPages(env) protected val renderNotFound = keyPages.notFound _ - implicit protected def LilaFunitToResult(@silent funit: Funit)(implicit ctx: Context): Fu[Result] = + implicit protected def LilaFunitToResult(@silent funit: Funit)(implicit req: RequestHeader): Fu[Result] = negotiate( html = fuccess(Ok("ok")), api = _ => fuccess(jsonOkResult) @@ -53,6 +53,11 @@ abstract private[controllers] class LilaController(val env: Env) implicit def ctxReq(implicit ctx: Context) = ctx.req implicit def reqConfig(implicit req: RequestHeader) = ui.EmbedConfig(req) + protected def EnableSharedArrayBuffer(res: Result): Result = res.withHeaders( + "Cross-Origin-Opener-Policy" -> "same-origin", + "Cross-Origin-Embedder-Policy" -> "require-corp" + ) + protected def NoCache(res: Result): Result = res.withHeaders( CACHE_CONTROL -> "no-cache, no-store, must-revalidate", EXPIRES -> "0" diff --git a/app/controllers/Puzzle.scala b/app/controllers/Puzzle.scala index bfe201ae49fc5..eba35519bf77d 100644 --- a/app/controllers/Puzzle.scala +++ b/app/controllers/Puzzle.scala @@ -33,7 +33,9 @@ final class Puzzle( private def renderShow(puzzle: PuzzleModel, mode: String)(implicit ctx: Context) = env.puzzle userInfos ctx.me flatMap { infos => renderJson(puzzle = puzzle, userInfos = infos, mode = mode, voted = none) map { json => - views.html.puzzle.show(puzzle, data = json, pref = env.puzzle.jsonView.pref(ctx.pref)) + EnableSharedArrayBuffer( + Ok(views.html.puzzle.show(puzzle, data = json, pref = env.puzzle.jsonView.pref(ctx.pref))) + ) } } @@ -43,9 +45,9 @@ final class Puzzle( _.map(_.id) ?? env.puzzle.api.puzzle.find }) { puzzle => negotiate( - html = renderShow(puzzle, "play") map { Ok(_) }, + html = renderShow(puzzle, "play"), api = _ => puzzleJson(puzzle) map { Ok(_) } - ) map { NoCache(_) } + ) map NoCache } } } @@ -53,14 +55,14 @@ final class Puzzle( def home = Open { implicit ctx => NoBot { env.puzzle.selector(ctx.me) flatMap { puzzle => - renderShow(puzzle, if (ctx.isAuth) "play" else "try") map { Ok(_) } + renderShow(puzzle, if (ctx.isAuth) "play" else "try") } } } def show(id: PuzzleId) = Open { implicit ctx => NoBot { - OptionFuOk(env.puzzle.api.puzzle find id) { puzzle => + OptionFuResult(env.puzzle.api.puzzle find id) { puzzle => renderShow(puzzle, "play") } } diff --git a/app/controllers/Relay.scala b/app/controllers/Relay.scala index 803373951ad10..0b3a391e7f8b8 100644 --- a/app/controllers/Relay.scala +++ b/app/controllers/Relay.scala @@ -116,7 +116,7 @@ final class Relay( chat <- studyC.chatOf(sc.study) sVersion <- env.study.version(sc.study.id) streams <- studyC.streamsOf(sc.study) - } yield Ok(html.relay.show(relay, sc.study, data, chat, sVersion, streams)) + } yield EnableSharedArrayBuffer(Ok(html.relay.show(relay, sc.study, data, chat, sVersion, streams))) } private def showRoute(r: RelayModel) = routes.Relay.show(r.slug, r.id.value) diff --git a/app/controllers/Study.scala b/app/controllers/Study.scala index ad338d39a7dc8..e9afba21184fc 100644 --- a/app/controllers/Study.scala +++ b/app/controllers/Study.scala @@ -150,7 +150,7 @@ final class Study( chat <- chatOf(sc.study) sVersion <- env.study.version(sc.study.id) streams <- streamsOf(sc.study) - } yield Ok(html.study.show(sc.study, data, chat, sVersion, streams)), + } yield EnableSharedArrayBuffer(Ok(html.study.show(sc.study, data, chat, sVersion, streams))), api = _ => chatOf(sc.study).map { chatOpt => Ok( diff --git a/app/controllers/UserAnalysis.scala b/app/controllers/UserAnalysis.scala index 4100dc02324e1..cf181039a32e1 100644 --- a/app/controllers/UserAnalysis.scala +++ b/app/controllers/UserAnalysis.scala @@ -44,7 +44,7 @@ final class UserAnalysis( val orientation = get("color").flatMap(chess.Color.apply) | pov.color env.api.roundApi .userAnalysisJson(pov, ctx.pref, decodedFen, orientation, owner = false, me = ctx.me) map { data => - Ok(html.board.userAnalysis(data, pov)) + EnableSharedArrayBuffer(Ok(html.board.userAnalysis(data, pov))) } }