Revert "play action name is no longer available since router simplification"
This reverts commit bca4dfcafa
.
pull/7412/head
parent
c5776af72f
commit
9a388388ed
|
@ -24,7 +24,7 @@ final class Lobby(
|
|||
Open { implicit ctx =>
|
||||
pageHit
|
||||
negotiate(
|
||||
html = env.pageCache("home") { () =>
|
||||
html = env.pageCache { () =>
|
||||
keyPages.homeHtml.dmap { html =>
|
||||
NoCache(Ok(html))
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ final class ErrorHandler(
|
|||
|
||||
override def onProdServerError(req: RequestHeader, exception: UsefulException) =
|
||||
Future {
|
||||
val actionName = "UnknownHandler"
|
||||
val actionName = HTTPRequest actionName req
|
||||
val client = HTTPRequest clientName req
|
||||
lila.mon.http.error(actionName, client, req.method, 500).increment()
|
||||
lila.log("http").error(s"ERROR 500 $actionName", exception)
|
||||
|
|
|
@ -31,7 +31,7 @@ final class HttpFilter(env: Env)(implicit val mat: Materializer) extends Filter
|
|||
}
|
||||
|
||||
private def monitoring(req: RequestHeader, startTime: Long, result: Result) = {
|
||||
val actionName = "UnknownHandler"
|
||||
val actionName = HTTPRequest actionName req
|
||||
val reqTime = nowMillis - startTime
|
||||
val statusCode = result.header.status
|
||||
val client = HTTPRequest clientName req
|
||||
|
|
|
@ -4,6 +4,7 @@ package http
|
|||
import play.api.mvc._
|
||||
import scala.concurrent.duration._
|
||||
|
||||
import lila.common.HTTPRequest
|
||||
import lila.api.Context
|
||||
|
||||
final class PageCache(cacheApi: lila.memo.CacheApi) {
|
||||
|
@ -12,14 +13,14 @@ final class PageCache(cacheApi: lila.memo.CacheApi) {
|
|||
_.expireAfterWrite(1.seconds).buildAsync()
|
||||
}
|
||||
|
||||
def apply(key: String)(compute: () => Fu[Result])(implicit ctx: Context): Fu[Result] =
|
||||
def apply(compute: () => Fu[Result])(implicit ctx: Context): Fu[Result] =
|
||||
if (ctx.isAnon && langs(ctx.lang.language) && defaultPrefs(ctx.req) && !hasCookies(ctx.req))
|
||||
cache.getFuture(cacheKey(key), _ => compute())
|
||||
cache.getFuture(cacheKey(ctx), _ => compute())
|
||||
else
|
||||
compute()
|
||||
|
||||
private def cacheKey(key: String)(implicit ctx: Context) =
|
||||
s"$key(${ctx.lang.language})"
|
||||
private def cacheKey(ctx: Context) =
|
||||
s"${HTTPRequest actionName ctx.req}(${ctx.lang.language})"
|
||||
|
||||
private def defaultPrefs(req: RequestHeader) =
|
||||
lila.pref.RequestPref.fromRequest(req) == lila.pref.Pref.default
|
||||
|
|
|
@ -2,6 +2,7 @@ package lila.common
|
|||
|
||||
import play.api.http.HeaderNames
|
||||
import play.api.mvc.RequestHeader
|
||||
import play.api.routing.Router
|
||||
|
||||
object HTTPRequest {
|
||||
|
||||
|
@ -96,6 +97,11 @@ object HTTPRequest {
|
|||
def acceptsNdJson(req: RequestHeader) = req.headers get HeaderNames.ACCEPT contains "application/x-ndjson"
|
||||
def acceptsJson(req: RequestHeader) = req.headers get HeaderNames.ACCEPT contains "application/json"
|
||||
|
||||
def actionName(req: RequestHeader): String =
|
||||
req.attrs.get(Router.Attrs.HandlerDef).fold("NoHandler") { handler =>
|
||||
s"${handler.controller.drop(12)}.${handler.method}"
|
||||
}
|
||||
|
||||
private val ApiVersionHeaderPattern = """application/vnd\.lichess\.v(\d++)\+json""".r
|
||||
|
||||
def apiVersion(req: RequestHeader): Option[ApiVersion] = {
|
||||
|
|
|
@ -25,7 +25,7 @@ final class CSRFRequestHandler(net: NetConfig) {
|
|||
}
|
||||
|
||||
private def monitor(tpe: String, req: RequestHeader) =
|
||||
lila.mon.http.csrfError(tpe, "UnknownHandler", clientName(req)).increment()
|
||||
lila.mon.http.csrfError(tpe, actionName(req), clientName(req)).increment()
|
||||
|
||||
private val topDomain = s"://${net.domain}"
|
||||
private val subDomain = s".${net.domain}"
|
||||
|
|
Loading…
Reference in New Issue