Skip to content

Commit

Permalink
Merge pull request #5787 from niklasf/coop-coep
Browse files Browse the repository at this point in the history
set coop/coep headers for multi-threaded stockfish (closes #5784)
  • Loading branch information
niklasf authored Dec 19, 2019
2 parents 57dc74a + c201b3e commit 12c8387
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
7 changes: 6 additions & 1 deletion app/controllers/LilaController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions app/controllers/Puzzle.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
)
}
}

Expand All @@ -43,24 +45,24 @@ 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
}
}
}

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")
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Relay.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/Study.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/UserAnalysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}

Expand Down

0 comments on commit 12c8387

Please sign in to comment.